視頻學習鏈接 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;