5.3 进阶3:排序查询

时间:2021-06-02 15:17:36   收藏:0   阅读:0

5.3 进阶3:排序查询

5.3.1 语法

select
	要查询的东西
from
	表
where 
	条件
order by 排序的字段|表达式|函数|别名 【asc|desc】

5.3.2 注意

5.3.3 案例

SELECT * FROM employees ORDER BY salary DESC;
SELECT * FROM employees ORDER BY salary ASC;
SELECT *
FROM employees
WHERE department_id >= 90
ORDER BY hiredatE ASC
SELECT *,salary*12*(1+IFNULL(commission_pct,0)) AS 年薪
FROM employees
ORDER BY salary*12*(1+IFNULL(commission_pct,0)) DESC
# 或者可以按照别名排序
ORDER BY 年薪
SELECT LENGTH(last_name) 字节长度,last_name,salary
FROM employees
ORDER BY 字节长度 DESC
SELECT *
FROM employees
ORDER BY salary ASC, employee_id DESC
select *
from employees
where email like ‘%e%‘
order by length(email) desc, department_id asc;
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!