SQL Order By

本文介绍了SQL中ORDER BY关键字的应用,包括如何按字母顺序和数字顺序对数据进行排序,以及如何使用DESC实现逆序排列。

The ORDER BY keyword is used to sort the result.
关键字ORDER BY可用来整理结果


Sort the Rows
将几条记录做整理

The ORDER BY clause is used to sort the rows.
ORDER BY 子句用来整理记录行

Orders:
定单数据库表:

CompanyOrderNumber
Sega3412
ABC Shop5678
W3pop2312
W3pop6798

举例

To display the companies in alphabetical order:
显示为按字母顺序排列:

SELECT Company, OrderNumber FROM Orders
ORDER BY Company

结果:

CompanyOrderNumber
ABC Shop 5678
Sega3412
W3pop6798
W3pop2312

举例

To display the companies in alphabetical order AND the ordernumbers in numerical order:
显示的结果按字母排序以及数字大小来排列:

SELECT Company, OrderNumber FROM Orders
ORDER BY Company, OrderNumber

结果:

CompanyOrderNumber
ABC Shop5678
Sega3412
W3pop2312
W3pop6798

举例

To display the companies in reverse alphabetical order:
显示出来的公司名称按字母反向排列:

SELECT Company, OrderNumber FROM Orders
ORDER BY Company DESC

结果:

CompanyOrderNumber
W3pop6798
W3pop2312
Sega3412
ABC Shop5678

举例

To display the companies in reverse alphabetical order AND the ordernumbers in numerical order:
显示的公司名称以及定单数都以反序排列

SELECT Company, OrderNumber FROM Orders
ORDER BY Company DESC, OrderNumber ASC

结果:

CompanyOrderNumber
W3pop2312
W3pop6798
Sega3412
ABC Shop5678
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值