当前位置:网站首页>使用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;
边栏推荐
猜你喜欢

Clock distribution of jesd204 IP core (ultrascale Series)
![[C语言刷题篇]链表运用讲解](/img/44/1de4e3f0712780680fbdc904dfe39a.png)
[C语言刷题篇]链表运用讲解

Raspberrypico serial communication

Simple example of C language 1

Raspberry pie 4B uses MNN to deploy yolov5 Lite

Unity package exe to read and write excel table files

读取json配置文件,实现数据驱动测试

Raspberry pie CM4 -- using metartc3.0 to integrate ffmpeg to realize webrtc push-pull streaming

数据挖掘(数据预处理篇)--笔记

[dynamic link library (DLL) initialization example program failed "problem]
随机推荐
[detailed use of doccano data annotation]
js网页黑白背景开关js特效
Raspberry pie 3b ffmpeg RTMP streaming
Raspberry pie 4B uses MNN to deploy yolov5 Lite
[pytorch] LSTM neural network
一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
MySQL error: specified key was too long; max key length is 767 bytes
Raspberry Pie 3 connected to WiFi
太空射击第14课: 玩家生命
C language data 3 (2)
Tree row expression
C language data 3 (1)
Regular symbol description
Raspberry pie creation self start service
Redis入门二:redhat 6.5安装使用
MySQL batch update data
字符设备驱动结构
Sorting out problems in interface endpoint testing practice using Supertest
Unity typewriter teaches you three ways
Simple example of C language 1