• 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>
  • 相关阅读:
    HDU 1358 Period
    HDU 1867 A + B for you again
    jquery的height()和javascript的height总结,js获取屏幕高度
    [前端] jquery验证手机号、身份证号、中文名称
    通过GitHub Pages建立个人站点(详细步骤)
    jQuery中多个元素的Hover事件
    jquery判断密码是否一致?
    php 5.6以上可以采用new PDD连接数据库的方法。
    如何学习html画布呢(canvas)
    跨年总结2015,明年就是2016了
  • 原文地址:https://www.cnblogs.com/zhulina-917/p/10091045.html
Copyright © 2020-2023  润新知