当前位置: 首页 > 网络学院 > 服务端脚本教程 > SQL > SQL Order By
The ORDER BY keyword is used to sort the result.
关键字ORDER BY可用来整理结果
The ORDER BY clause is used to sort the rows.
ORDER BY 子句用来整理记录行
Orders:
定单数据库表:
Company | OrderNumber |
---|---|
Sega | 3412 |
ABC Shop | 5678 |
RuanChen | 2312 |
RuanChen | 6798 |
To display the companies in alphabetical order:
显示为按字母顺序排列:
SELECT Company, OrderNumber FROM Orders |
结果:
Company | OrderNumber |
---|---|
ABC Shop | 5678 |
Sega | 3412 |
RuanChen | 6798 |
RuanChen | 2312 |
To display the companies in alphabetical order AND the ordernumbers in numerical order:
显示的结果按字母排序以及数字大小来排列:
SELECT Company, OrderNumber FROM Orders |
结果:
Company | OrderNumber |
---|---|
ABC Shop | 5678 |
Sega | 3412 |
RuanChen | 2312 |
RuanChen | 6798 |
To display the companies in reverse alphabetical order:
显示出来的公司名称按字母反向排列:
SELECT Company, OrderNumber FROM Orders |
结果:
Company | OrderNumber |
---|---|
RuanChen | 6798 |
RuanChen | 2312 |
Sega | 3412 |
ABC Shop | 5678 |
To display the companies in reverse alphabetical order AND the ordernumbers in numerical order:
显示的公司名称以及定单数都以反序排列
SELECT Company, OrderNumber FROM Orders |
结果:
Company | OrderNumber |
---|---|
RuanChen | 2312 |
RuanChen | 6798 |
Sega | 3412 |
ABC Shop | 5678 |