/*
语法:
select 查询列表
from 表
where 筛选条件
order by 排序列表 asc | desc
*/
# 案例:查询员工信息,工资从高到低排序
SELECT * FROM employees ORDER BY salary DESC;
SELECT * FROM employees ORDER BY salary ASC;
#案例2:【添加筛选条件】查询部门编号>=90的员工信息,按入职时间的先后进行排序
SELECT *
FROM employees
WHERE department_id >= 90
ORDER BY hiredate ASC;
#案例3:【按表达式排序】按年薪的高低显示员工的信息和年薪
SELECT *, salary*12*(IFNULL(commission_pct,0) + 1) AS 年薪
FROM employees
ORDER BY salary*12*(IFNULL(commission_pct,0) + 1) DESC;
#案例4;【按别名排序】按年薪的高低显示员工的信息和年薪
SELECT *, salary*12*(IFNULL(commission_pct,0) + 1) AS 年薪
FROM employees
ORDER BY 年薪 DESC;
#案例5:按姓名的长度去显示员工的姓名和工资【按函数排序】
SELECT LENGTH(last_name) AS 字节长度,last_name,salary
FROM employees
ORDER BY 字节长度 DESC;
#案例6:查询员工信息,要求先按工资升序,再按员工编号降序【按多个字段排序】
SELECT *
FROM employees
ORDER BY salary ASC, employee_id DESC;