首页 小组 文章 相册 留言本 用户 搜索 我的社区 在线学堂 商城 购物车 支付钱包

[分享]软件4班_排序与分页

2024-04-02 12:09:27
0
284

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

评论
意见反馈