进阶三:排序查询
引入:
SELECT * FROM 表名;
SELECT * FROM employees ORDER BY salary ASC;
SELECT * FROM employees WHERE department_id >= 90 ORDER BY hiredate ASC;
(salary*12*(1+IFNULL(commission_pct,0))解析:ifnull:如果是null的话,用0代替提成:如果没有薪水的话乘以0,有的话乘以1+提成
SELECT * FROM employees ORDER BY (salary*12*(1+IFNULL(commission_pct,0))) DESC;
SELECT *,(salary*12*(1+IFNULL(commission_pct,0))) AS 年薪 FROM employees ORDER BY 年薪 DESC;
SELECT *,(salary*12*(1+IFNULL(commission_pct,0))) AS 年薪 FROM employees ORDER BY (salary*12*(1+IFNULL(commission_pct,0))) DESC;
SELECT * FROM employees ORDER BY LENGTH(CONCAT(first_name,last_name)) DESC;
SELECT * FROM employees ORDER BY salary DESC, employee_id ASC;
USE myemployees;
SELECT last_name, department_id, salary FROM employees ORDER BY (salary * (1 + IFNULL(commission_pct,0)) * 12) DESC , last_name ASC;
SELECT last_name, salary FROM employees WHERE !(salary >= 8000 AND salary <= 17000) ORDER BY salary 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;