基本操作
SELECT * FROM employees ORDER BY salary DESC;
SELECT *
FROM employees
WHERE department_id >= 90
ORDER BY hiredate ASC;
SELECT *,salary*12*(1+IFNULL(commission_pct,0))
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 LENGTH(last_name) AS 字节长度,last_name,salary
FROM employees
ORDER BY LENGTH(last_name) DESC;
SELECT *
FROM employees
ORDER BY salary ASC,employee_id DESC;
练习
SELECT last_name,department_id,salary*12*(1+IFNULL(commission_pct,0)) AS 年薪
FROM employees
ORDER BY 年薪 DESC,last_name ASC;
SELECT last_name,salary
FROM employees
WHERE salary NOT BETWEEN 8000 AND 17000
ORDER BY salary DESC;
SELECT *,LENGTH(email) AS 邮箱
FROM employees
WHERE email LIKE '%e%'
ORDER BY 邮箱 DESC,department_id ASC;