排序
SELECT employee_id, first_name, last_name, hire_date, salary
FROM employees
ORDER BY first_name;
ORDER BY hire_date ASC;
ORDER BY hire_date DESC;
SELECT employee_id, first_name, last_name, hire_date, salary
FROM employees
ORDER BY first_name, last_name DESC
SELECT employee_id, first_name, last_name, hire_date, salary
FROM employees
ORDER BY 2, 3 DESC
SELECT employee_id, manager_id
FROM employees
ORDER BY manager_id DESC;
SELECT employee_id, manager_id
FROM employees
ORDER BY manager_id NULLS FIRST;
返回top
SELECT first_name, last_name, salary
FROM employees
ORDER BY salary
LIMIT 10;
SELECT first_name, last_name, salary
FROM employees
ORDER BY salary
FETCH FIRST 10 ROWS WITH TIES;
SELECT first_name, last_name, salary
FROM employees
ORDER BY salary
OFFSET 10 ROWS
FETCH FIRST 10 ROWS ONLY;
SELECT first_name, last_name, salary
FROM employees
ORDER BY salary
LIMIT 10 OFFSET 10;
条件表达case
SELECT first_name, last_name,
CASE
WHEN salary <5000 THEN '低收入'
WHEN salary between 5000 and 100000 THEN '中等收入'
ELSE '高收入'
END AS "收入等级"
FROM employees;
SELECT COUNT(CASE department_id WHEN 10 THEN 1 END) dep_cnt_10,
COUNT(CASE department_id WHEN 20 THEN 1 END) dep_cnt_20,
COUNT(CASE department_id WHEN 30 THEN 1 END) dep_cnt_30
FROM employees;