排序
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;
汇总统计
SELECT COUNT(*), SUM(salary), AVG(SALARY), MAX(salary), MIN(salary)
FROM employees;
SELECT COUNT(*), COUNT(manager_id) FROM employees;
SELECT COUNT(DISTINCT manager_id) FROM employees;
SELECT STRING_AGG(first_name, ';') FROM employees;
SELECT STRING_AGG(first_name, ';' ORDER BY first_name) FROM employees;