程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> SQL: ORDER BY Clause

SQL: ORDER BY Clause

編輯:關於SqlServer
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 歡迎光臨學網,收藏本篇文章 [1] [2] [3]

$False$

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.
譯:返回以pt">supplier_city為降序、supplIEr_state為二級升序的結果。 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved