第05章_排序与分页
1. 排序
SELECT * FROM employees;
SELECT employee_id,last_name,salary
FROM employees
ORDER BY salary DESC;
SELECT employee_id,last_name,salary
FROM employees
ORDER BY salary ASC;
SELECT employee_id,last_name,salary
FROM employees
ORDER BY salary;
SELECT employee_id,salary,salary * 12 annual_sal
FROM employees
ORDER BY annual_sal;
SELECT employee_id,salary,salary * 12 annual_sal
FROM employees
WHERE annual_sal > 81600;
SELECT employee_id,salary
FROM employees
WHERE department_id IN (50,60,70)
ORDER BY department_id DESC;
SELECT employee_id,salary,department_id
FROM employees
ORDER BY department_id DESC,salary ASC;
2. 分页
SELECT employee_id,last_name
FROM employees
LIMIT 0,20;
SELECT employee_id,last_name
FROM employees
LIMIT 20,20;
SELECT employee_id,last_name
FROM employees
LIMIT 40,20;
SELECT employee_id,last_name,salary
FROM employees
WHERE salary > 6000
ORDER BY salary DESC
LIMIT 10;
SELECT employee_id,last_name
FROM employees
LIMIT 31,2;
SELECT employee_id,last_name
FROM employees
LIMIT 2 OFFSET 31;
SELECT employee_id,last_name,salary
FROM employees
ORDER BY salary DESC
LIMIT 1;