#进阶3:排序查询
/*
引入:
seclet *from employees;
语法:
select 查询列表
from 表
where 筛选条件
order by 排序列表 asc(升序)|desc(降序)
1.不写默认升序
2.支持多字段排序、表达式、别名
3.一般放查询语句最后,limit除外。
*/
#案例1:查询员工信息,工资从高到低排序
SELECT *FROM `employees` ORDER BY`salary` DESC;
#案例2:查询部门编号大于90 的员工信息,按入职时间先后排序
SELECT * FROM`employees` WHERE `department_id`>= 90 ORDER BY `hiredate`
#案例三:按年薪的高低显示员工信息和年薪【按表达式排序】
SELECT *,salary*12*(1+IFNULL(`commission_pct`,0)) AS 年薪
FROM `employees`ORDER BY salary*12*(1+IFNULL(`commission_pct`,0)) DESC;
#案例四 :按姓名长度显示姓名和工资【按函数排序】
SELECT LENGTH (`last_name`),`last_name`,`salary`
FROM `employees`
ORDER BY LENGTH (`last_name`) DESC;
#案例五:查看员工信息,要求先按工资,再按员工id[多字段排序]
SELECT * FROM `employees`
ORDER BY `salary`ASC ,`employee_id` DESC;
#练习
SELECT LENGTH(`last_name`),`last_name`,`department_id`,`salary`*12*(1+IFNULL(`commission_pct`,0))AS 年薪
FROM`employees` ORDER BY 年薪 ASC,LENGTH(`last_name`)DESC;
SELECT `last_name`,`salary` FROM `employees` WHERE `salary`NOT BETWEEN 8000 AND 17000
ORDER BY `salary` DESC;
SELECT * FROM `employees` WHERE`email`LIKE '%e%'
ORDER BY LENGTH(`email`)DESC , `department_id` ASC;