1.数据库来源:Mysql 基础教程
2.数据库说明:
本文使用的第一个数据库名称为 myemployees,其中有 8 张表,分别为 customers 表,departments 表,employees 表,job_grades 表,jobs 表,locations 表,orders 表,salespeople 表。
一、分页查询基本语法
select 查询列表
from 表1
join type join 表2
on 连接条件
where 筛选条件
group by 分组字段
having 分组后的筛选
order by 排序的字段
limit offset,size
二、分组查询特点
① offset:表示要显示条目的起始索引(起始索引从 0 开始)
② size:表示要显示的条目个数
③ limit 语句放在查询语句的最后
三、分组查询相关案例(仅展示有限部分)
案例一:查询前 5 条员工信息
select * from employees
limit 5
案例二:查询第 11 条到第 25 条员工信息
select * from employees
limit 10, 15
案例三:查询有奖金的,工资较高的前 10 名员工的信息
select * from employees
where commission_pct is not null
order by salary desc
limit 10