SELECT * from employees;
-- 排序用order by
SELECT employee_id,salary,department_id
from employees;
-- 只用order by 默认是升序
SELECT employee_id,department_id,salary
from employees ORDER BY salary;
-- DESC 降序
SELECT employee_id,department_id,salary
from employees ORDER BY salary DESC;
-- ASC 升序
SELECT employee_id,department_id,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,department_id
ept_id
from employees
where dept_id > 50
ORDER BY dept_id 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条开始 这一页有10条数据(2页)
SELECT employee_id,salary
from employees
LIMIT 10,10;
-- 第21条开始,这一页有10条数据 (3页)
SELECT employee_id,salary
from employees
LIMIT 20,10;
-- 第14条开始,这一页有8条数据
SELECT employee_id,salary
from employees
LIMIT 13,8;
SELECT employee_id,salary
from employees
LIMIT 8 OFFSET 13;
(3-1)*10,10 = 20,10
(2-1)*10,10 = 10,10