霍格沃兹测试开发学社
ceshiren.com
-- 展示前 10 条员工信息
SELECT * FROM employees LIMIT 10;
SELECT * FROM employees LIMIT 0, 10;
SELECT * FROM employees LIMIT 10 OFFSET 0;
-- 显示年薪从高到低排序,第 15 位到第 20 位员工的编号和年薪
SELECT
emp_no, salary
FROM
salaries
ORDER BY salary DESC
LIMIT 14, 6;
SELECT
emp_no, salary
FROM
salaries
ORDER BY salary DESC
LIMIT 6 OFFSET 14;
@startuml
autonumber
原始数据库 -> 虚拟表1: FROM 子句
虚拟表1 -> 虚拟表2: WHERE 子句
虚拟表2 -> 虚拟表3: GROUP BY 子句
虚拟表3 -> 虚拟表4: HAVING 子句
虚拟表4 -> 虚拟表5: SELECT
虚拟表5 -> 虚拟表6: DISTINCT
虚拟表6 -> 虚拟表7: ORDER BY 子句
虚拟表7 -> 最终结果: LIMIT
@enduml