zoukankan      html  css  js  c++  java
  • sql中limit使用方法

    引用博主https://www.cnblogs.com/yoyoblogs/p/5828651.html的文章
    sql中limit 的使用方法
    此处以mysql为例,但是我相信物以变通在oracle上也一定适用

    1、下面是几种limit的方法:原则看看下面几个例子应该就懂了

    在数据库中很多地方都会用到,比如当你数据库查询记录有几万、几十万时使用limit查询效率非常快,只需要查询出你需要的数据就可以了·再也不用全表查询导致查询数据库崩溃的情况。

    select * from Customer LIMIT 10;--检索前10行数据,显示1-10条数据
    select * from Customer LIMIT 1,10;--检索从第2行开始,累加10条id记录,共显示id为2....11
    select * from Customer limit 5,10;--检索从第6行开始向前加10条数据,共显示id为6,7....15
    select * from Customer limit 6,10;--检索从第7行开始向前加10条记录,显示id为7,8...16

    2、sql中update的用法

    1)、需求:如果我想更新id=1status1id不为1status ,且id有外键

    update AccountStatus a set a.statusSource=(case when a.statusSource =1 then 2 else  1 end )

    --这样可以替换掉id为1的数据为0,id为0的数据为1

     

    3、反例

    追加:

    select * from Customer limit 10,5;--检索从第10行开始向前加5条数据,共显示id为11,12...15

     

    附加上一个小例子
    <resultMap id="newslabelMapParent" type="NewsLabel"> <id column="id" property="id"/> <result column="label_name" property="name"/> <result column="label_content" property="content"/> <association property="parent" javaType="NewsLabel" select="selectNewslabelById" column="pid"/> </resultMap> <select id="selectNewsLabelsCurrentPage" resultMap="newslabelMapParent"> select id, label_name, label_content, pid from newlabel <if test="ppid != 0"> where pid = #{ppid} </if> limit #{pageStartIndex},#{pageSize} </select>
  • 相关阅读:
    excelhelp
    导入数据到GridView
    sql2005悠改sa
    状态存储管理 encode,decode,transfer
    Session持久化
    Microsoft SQL Server 2005 数据类型
    Cookie (HttpCookie的实例)
    role设计
    ajax
    poj 3370 Halloween treats 夜
  • 原文地址:https://www.cnblogs.com/zhulina-917/p/10091045.html
Copyright © 2011-2022 走看看