视频学习链接 https://www.bilibili.com/video/av59623481/?p=42
语法:
select
要查询的东西
from
表
where
条件
order by 排序的字段|表达式|函数|别名 【asc|desc】
特点:
1. asc表示升序,desc表示降序,默认是升序
2. order by子句支持单个字段、多个字段、表达式、函数、别名
3. order by子句一般是放在查询语句的最后面,limit子句除外
例:SELECT * FROM employees ORDER BY salary ASC;
1. 按多个字段排序:SELECT * FROM employees ORDER BY salary ASC, employee_id DESC;
2. 按表达式排序(或别名):SELECT *, salary*(1+IFNULL(commission_pct,0))*12 AS 年薪 FROM employees ORDER BY 年薪 DESC;
3. 按函数排序:SELECT LENGTH(last_name) AS 字节长度, last_name, salary FROM employees ORDER BY LENGTH(last_name) DESC;