zoukankan      html  css  js  c++  java
  • 22 limit(重点中的重点,以后分页查询全靠它了。)

    22 limit(重点中的重点,以后分页查询全靠它了。)
        limit是mysql特有的,其他数据中没有,不通用。(orcale中有一个相同的机制,叫做rownum)
        
        limit取结果集中的部分数据,这是他的作用。
        
        语法机制:
            limit startIndex,length
                startIndex表示起始位置,从0开始,0表示第一个数据。
                length表示取几个
        
        案例:取出工资前五名(思路:降序取出前五个)
            select ename,sal from emp order by sal desc;
            
            取前五个:
            select ename,sal from emp order by sal desc limit 0,5;
            select ename,sal from emp order by sal desc limit 5;
                +-------+---------+
                | ename | sal     |
                +-------+---------+
                | KING  | 5000.00 |
                | SCOTT | 3000.00 |
                | FORD  | 3000.00 |
                | JONES | 2975.00 |
                | BLAKE | 2850.00 |
                +-------+---------+
                
            limit是sql语句最后执行的一个环节:
            
                select
                    ...    5
                from
                    ...    1
                where
                    ...    2
                group by
                    ...    3
                having
                    ...    4
                order by
                    ...    6
                limit
                    ...    7;
                    
        案例:找出工资排名在第四到第九名的员工?
            select ename,sal from emp order by sal desc limit 3,6;
                +--------+---------+
                | ename  | sal     |
                +--------+---------+
                | JONES  | 2975.00 |
                | BLAKE  | 2850.00 |
                | CLARK  | 2450.00 |
                | ALLEN  | 1600.00 |
                | TURNER | 1500.00 |
                | MILLER | 1300.00 |
                +--------+---------+
                
        通用的标准分页sql?
        
        每页显示3条记录:
        第1页:0,3
        第2页:3,3
        第3页:6,3
        第4页:9,3
        第5页:12,3
        
        每页显示pageSize条记录:
        第pageNo页: (pageNo - 1) * pageSize,pageSize
        
        pageSize是什么?是每页显示多少条记录
        pageNo是什么?显示第几页
  • 相关阅读:
    SVN 、Git、Github的使用
    asp.net core 系列 8 Razor框架路由(下)
    asp.net core 系列 7 Razor框架路由(上)
    asp.net core 系列 6 MVC框架路由(下)
    asp.net core 系列 5 MVC框架路由(上)
    asp.net core 系列 4 注入服务的生存期
    asp.net core 系列 3 依赖注入服务
    asp.net core 系列 2 启动Startup类介绍
    asp.net core 系列 1 概述
    iframe和response.sendRedirect()跳转到父页面的问题
  • 原文地址:https://www.cnblogs.com/xlwu/p/13639651.html
Copyright © 2011-2022 走看看