#进阶3:排序查询 /* 语法: SELECT FROM WHERE ORDER BY ASC|DESC */ USE myemployees; #案例1:查询员工信息,按工资从高到低排 SELECT * FROM employees ORDER BY salary; #案例2:查询部门编号>=90的员工信息,按入职时间的先后排序 SELECT * FROM employees WHERE department_id >= 90 ORDER BY hiredate; #案例3:按年薪高低显示员工信息和年薪 SELECT *, salary*12*(1+IFNULL(commission_pct, 0)) AS 年薪 FROM employees ORDER BY 年薪 DESC; #案例4:按姓名长度排序 SELECT *, salary*12*(1+IFNULL(commission_pct, 0)) AS 年薪 FROM employees ORDER BY Length(last_name); #案例5:查询员工信息,先按工资、再按员工编号 SELECT * FROM employees ORDER BY salary, employee_id DESC; SELECT * FROM employees ORDER BY salary DESC, employee_id; #案例6:工资不带8000到17000之间的员工的姓名和工资,按工资降序 SELECT Concat(last_name, ' ', first_name) AS "name", salary FROM employees WHERE salary NOT BETWEEN 8000 AND 17000 ORDER BY salary DESC;