网络学院 w3pop社区 网络资源 IT新闻

w3pop.com :: 网络学院 :: SQL :: SQL Order By

会员登陆

帐号

密码

回答

记住密码

忘记密码? 注册

SQL
SQL Create View
SQL Server
SQL 速查
SQL 摘要
MYSQL 列类型存储..

SQL Order By


作者:w3pop.com 翻译/整理:w3pop.com 发布:2007-04-28 浏览:4232 :: ::

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:
定单数据库表:

Company OrderNumber
Sega 3412
ABC Shop 5678
W3pop 2312
W3pop 6798

举例

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

SELECT Company, OrderNumber FROM Orders
ORDER BY Company

结果:

Company OrderNumber
ABC Shop  5678
Sega 3412
W3pop 6798
W3pop 2312

举例

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

SELECT Company, OrderNumber FROM Orders
ORDER BY Company, OrderNumber

结果:

Company OrderNumber
ABC Shop 5678
Sega 3412
W3pop 2312
W3pop 6798

举例

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

SELECT Company, OrderNumber FROM Orders
ORDER BY Company DESC

结果:

Company OrderNumber
W3pop 6798
W3pop 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
ORDER BY Company DESC, OrderNumber ASC

结果:

Company OrderNumber
W3pop 2312
W3pop 6798
Sega 3412
ABC Shop 5678

评论 (0) All