数据库-排序查询
• 语法:select 查询列表
from 表
【where 筛选条件】
order by 排序列表 【asc|desc】
• 特点:
1.asc代表的是升序,desc代表的是降序。
如果不写,默认是升序。
2.order by子句中可以支持单个字段、多个字段、表达式、函数、别名。
3.order by子句一般是放在查询语句的最后面,但limit子句除外。
SELECT * FROM employees ORDER BY salary DESC;
SELECT *
FROM employees
WHERE `department_id` >= 90
ORDER BY `hiredate` ASC;
SELECT *,salary*12*(1 + IFNULL(`commission_pct`,0)) AS 年薪
FROM employees
ORDER BY salary*12*(1 + IFNULL(`commission_pct`,0)) DESC;
SELECT *,salary*12*(1 + IFNULL(`commission_pct`,0)) AS 年薪
FROM employees
ORDER BY 年薪 DESC;
SELECT LENGTH(last_name) 字节长度,last_name,salary
FROM employees
ORDER BY LENGTH(last_name) DESC;
SELECT *
FROM employees
ORDER BY salary ASC,`employee_id` DESC;