MySQL排序和分页(浅入浅出)

排序规则 使用 ORDER BY 子句排序

ASC(ascend): 升序(默认)

DESC(descend):降序

ORDER BY 子句在SELECT语句的结尾。

单列排序

SELECT   last_name, job_id, department_id, hire_date
FROM employees
ORDER BY hire_date ;
SELECT   last_name, job_id, department_id, hire_date
FROM employees
ORDER BY hire_date DESC ;

SELECT employee_id, last_name, salary*12 annsal
FROM employees
ORDER BY annsal;

多列排序

SELECT last_name, department_id, salary
FROM employees
ORDER BY department_id, salary DESC;