一、分页查询
应用场景:当要显示的数据,一页显示不全,需要分页提交sql请求
语法:
select 查询列表
from 表
【join type join 表2 on 连接条件
where 筛选条件
group by 分组字段
having 分组后的筛选
order by 排序的字段】
limit offset,size;
 
offset表示要显示条目的起始索引(起始索引从0开始)
size表示要显示的条目个数
特点:
1、limit语句放在查询语句的最后
2、公式
要显示的页数page,每页的条目数size
select 查询列表
from 表
limit (page-1)*size,size;
 
size=10
page offset
1 0
2 10
3 20
 
二、案例
# 案例1:查询前5条员工信息 
select * from employees limit 0,5; select * from employees limit 5,5;
# 案例2:有奖金的员工信息,并且工资较高的前10名显示出来
select * from employees where commission_pct is not null order by salary desc limit 10;

 

 
三、sql执行顺序
0
 
posted on 2022-07-17 22:06  时光以北暮南城  阅读(254)  评论(0编辑  收藏  举报