当前位置:网站首页>使用ORDER BY 排序
使用ORDER BY 排序
2022-07-28 18:41:00 【richest_qi】
ASC(ascent),升序排序;DESC(descent),降序排序。如果没有显式声明ORDER BY的排序顺序,则默认是升序排序,相当于ORDER BY xxx ASC。ORDER BY可以使用列的别名,可以使用列的别名进行排序。SELECT ... FROM ... WHERE ... ORDER BY...。ORDER BY在WHERE后面。ORDER BY可以使用列的别名,WHERE不能使用列的别名。- 多列排序,用逗号分隔。比如,
ORDER BY xxx DESC,yyy ASC。
DESC降序,ASC升序
- 按照salary从高到低进行排序。
# 按照salary从高到低排序
SELECT last_name,salary
FROM employees
ORDER BY salary DESC;
- 按照salary从低到高进行排序。
# 按照salary从低到高排序
SELECT last_name,salary
FROM employees
ORDER BY salary ASC;
SELECT last_name,salary
FROM employees
ORDER BY salary;
ORDER BY 使用列的别名排序
# 按照年薪从高到低进行排序
SELECT last_name,salary,12*salary*(1+IFNULL(commission_pct,0)) annual_salary
FROM employees
ORDER BY annual_salary DESC;
ORDER BY 在 WHERE 后面
# department_id为10或20或30的员工的年收入从高到底排序
SELECT department_id,last_name,salary,12*salary*(1+IFNULL(commission_pct,0)) annual_salary
FROM employees
WHERE department_id IN (10,20,30)
ORDER BY annual_salary DESC;
以上MySQL语句的执行顺序为,
第1步:FROM。
第2步:WHERE。
第3步:SELECT。
第4步:ORDER BY。
ORDER BY 多列排序,用逗号分隔
- 按照department_id降序排列
# 显示员工信息,按照department_id降序排列
SELECT department_id,last_name,salary
FROM employees
ORDER BY department_id DESC;
- 按照department_id降序排列,再按照salary升序排列(department_id相同时,按照salary升序排列)
SELECT department_id,last_name,salary
FROM employees
ORDER BY department_id DESC,salary ASC;
边栏推荐
- Related concepts of multitasking programming
- Raspberry pie 4B deploy yolov5 Lite using ncnn
- 上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展
- Yum package management
- Raspberry pie 4B parsing PWM
- Residual network RESNET source code analysis - pytoch version
- Does any elder brother know how to solve the huge flinksql log
- js网页黑白背景开关js特效
- Unity uses shader to quickly make a circular mask
- Use of DDR3 (axi4) in Xilinx vivado (3) module packaging
猜你喜欢

Explain RESNET residual network in detail

【CodeForces】Educational Codeforces Round 132 (Rated for Div. 2)

Unity makes prefabricated bodies with one key and modifies prefabricated bodies with one key

Data mining (data preprocessing) -- Notes

Unity gadget displays the file size of the resource directory

一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力

PXE_ KS unattended system
![[pytorch] LSTM neural network](/img/c8/c1f92e7d4da7f07b85abe481f025bc.png)
[pytorch] LSTM neural network

Linxu 【权限,粘滞位】

js可拖拽alert弹窗插件
随机推荐
js可拖拽alert弹窗插件
MySQL batch update data
太空射击第14课: 玩家生命
System. ArgumentException: Object of type ‘System. Int64‘ cannot be converted to type ‘System.Int32‘
Character device drive structure
Redis 3.0源码分析-数据结构与对象 SDS LIST DICT
Raspberry connects EC20 for PPP dialing
Raspberry pie 4B uses MNN to deploy yolov5 Lite
Scheduled backup of MySQL database under Windows system
PXE_ KS unattended system
Product manager interview | innovation and background of the fifth generation verification code
C# 读取 CSV文件内数据,导入DataTable后显示
Use of DDR3 (axi4) in Xilinx vivado (4) incentive design
LeetCode-297-二叉树的序列化与反序列化
Classes and objects (medium)
C language data 3 (1)
树行表达方式
Regular symbol description
关于链接到其他页面的标题
根据openGauss/MogDB的lwtid查看线程堆栈。