SQL: ORDER BY Clause

35 篇文章 0 订阅
32 篇文章 1 订阅
 
SQL: ORDER BY Clause

The ORDER BY clause allows you to sort the records in your result set. The ORDER BY clause can only be used in SELECT statements.
译: ORDER BY 允许你在结果集中对记录进行排序。 ORDER BY 只能够用于 SELECT 语句。
The syntax for the ORDER BY clause is:
译: ORDER BY 的语法如下:
SELECT columns
FROM tables
WHERE predicates
ORDER BY column ASC/DESC;
The ORDER BY clause sorts the result set based on the columns specified. If the ASC or DESC value is omitted, the system assumed ascending order.
译: ORDER BY 是根据指定的列进行排序。如果省略 ASC 或者 DESC ,系统默认为升序。
ASC indicates ascending order. (default)
DESC indicates descending order.
译: ASC 表明升序(默认)
DESC
表明降序。
 
Example #1
SELECT supplier_city
FROM supplier
WHERE supplier_name = 'IBM'
ORDER BY supplier_city;
This would return all records sorted by the supplier_city field in ascending order.
译:结果将会以 supplier_city 排序的升序结果返回所有记录。
Example #2
SELECT supplier_city
FROM supplier
WHERE supplier_name = 'IBM'
ORDER BY supplier_city DESC;
This would return all records sorted by the supplier_city field in descending order.
译:以 supplier_city 的降序结果返回所有记录。
Example #3
You can also sort by relative position in the result set, where the first field in the result set is 1. The next field is 2, and so on.
译:你可以采用字段的相对位置作为排序,第一个字段为 1 ,下一个为 2 等等。
SELECT supplier_city
FROM supplier
WHERE supplier_name = 'IBM'
ORDER BY 1 DESC;
This would return all records sorted by the supplier_city field in descending order, since the supplier_city field is in position #1 in the result set.
译:这样会以 supplier_city 的降序返回所有结果,因为 supplier_city 在结果集中的位置是 #1
Example #4
SELECT supplier_city, supplier_state
FROM supplier
WHERE supplier_name = 'IBM'
ORDER BY supplier_city DESC, supplier_state ASC;
This would return all records sorted by the supplier_city field in descending order, with a secondary sort by supplier_state in ascending order.
译:返回以 supplier_city 为降序、 supplier_state 为二级升序的结果。
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值