SELECT * from employees;
SELECT employee_id,salary
from employees;
-- 排序用到ORDER BY
-- 只用ORDER BY 默认是升序
SELECT employee_id,last_name,salary
from employees
ORDER BY salary;
-- DESC 降序
SELECT employee_id,last_name,salary
from employees
ORDER BY salary DESC;
-- ASC 升序
SELECT employee_id,last_name,salary
from employees
ORDER BY salary ASC;
SELECT employee_id,salary*12 year_salary
from employees;
-- 列别名不能在where里使用
SELECT employee_id,salary*12 year_salary
from employees
where year_salary > 50000;
-- 列别名能在ORDER BY 使用
SELECT employee_id,salary*12 year_salary
from employees
ORDER BY year_salary DESC;
SELECT employee_id,salary*12 year_salary
from employees
ORDER BY year_salary;
SELECT employee_id,salary
from employees
where salary > 6000
ORDER BY salary DESC;
SELECT employee_id,salary sal
from employees
where sal > 6000
ORDER BY sal DESC;
SELECT employee_id,salary,department_id
FROM employees
ORDER BY department_id ,salary ,,,,,,;
SELECT employee_id,salary
FROM employees;
-- 第一页
SELECT employee_id,salary
FROM employees
LIMIT 0,10;
SELECT employee_id,salary
FROM employees
LIMIT 10;
-- 第二页 第11条到第20条
SELECT employee_id,salary
FROM employees
LIMIT 10,10
-- 第三页 第21条到第30条
SELECT employee_id,salary
FROM employees
LIMIT 20,10;
SELECT employee_id,salary
FROM employees
LIMIT 10 OFFSET 20;
-- 第5条到第12条
SELECT employee_id,salary
FROM employees
LIMIT 4,8;
/*
第一页 (1-1)*10,10 0,10
第二页 (2-1)*10,10 10,10
第三页 (3-1)*10,10 20,10
*/