新聞中心
impala ORDER BY子句用于根據(jù)一個(gè)或多個(gè)列以升序或降序?qū)?shù)據(jù)進(jìn)行排序。 默認(rèn)情況下,一些數(shù)據(jù)庫(kù)按升序?qū)Σ樵兘Y(jié)果進(jìn)行排序。

甕安網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,甕安網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為甕安上千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的甕安做網(wǎng)站的公司定做!
語(yǔ)法
以下是ORDER BY子句的語(yǔ)法。
select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]
可以使用關(guān)鍵字ASC或DESC分別按升序或降序排列表中的數(shù)據(jù)。
以同樣的方式,如果我們使用NULLS FIRST,表中的所有空值都排列在頂行; 如果我們使用NULLS LAST,包含空值的行將最后排列。
例
假設(shè)我們?cè)跀?shù)據(jù)庫(kù)my_db中有一個(gè)名為customers的表,其內(nèi)容如下 -
[quickstart.cloudera:21000] > select * from customers; Query: select * from customers +----+----------+-----+-----------+--------+ | id | name | age | address | salary | +----+----------+-----+-----------+--------+ | 3 | kaushik | 23 | Kota | 30000 | | 1 | Ramesh | 32 | Ahmedabad | 20000 | | 2 | Khilan | 25 | Delhi | 15000 | | 6 | Komal | 22 | MP | 32000 | | 4 | Chaitali | 25 | Mumbai | 35000 | | 5 | Hardik | 27 | Bhopal | 40000 | +----+----------+-----+-----------+--------+ Fetched 6 row(s) in 0.51s
以下是使用order by子句按照其ID的升序排列customers表中的數(shù)據(jù)的示例。
[quickstart.cloudera:21000] > Select * from customers ORDER BY id asc;
在執(zhí)行時(shí),上述查詢產(chǎn)生以下輸出。
Query: select * from customers ORDER BY id asc +----+----------+-----+-----------+--------+ | id | name | age | address | salary | +----+----------+-----+-----------+--------+ | 1 | Ramesh | 32 | Ahmedabad | 20000 | | 2 | Khilan | 25 | Delhi | 15000 | | 3 | kaushik | 23 | Kota | 30000 | | 4 | Chaitali | 25 | Mumbai | 35000 | | 5 | Hardik | 27 | Bhopal | 40000 | | 6 | Komal | 22 | MP | 32000 | +----+----------+-----+-----------+--------+ Fetched 6 row(s) in 0.56s
同樣,您可以使用order by子句按降序排列customers表的數(shù)據(jù),如下所示。
[quickstart.cloudera:21000] > Select * from customers ORDER BY id desc;
在執(zhí)行時(shí),上述查詢產(chǎn)生以下輸出。
Query: select * from customers ORDER BY id desc +----+----------+-----+-----------+--------+ | id | name | age | address | salary | +----+----------+-----+-----------+--------+ | 6 | Komal | 22 | MP | 32000 | | 5 | Hardik | 27 | Bhopal | 40000 | | 4 | Chaitali | 25 | Mumbai | 35000 | | 3 | kaushik | 23 | Kota | 30000 | | 2 | Khilan | 25 | Delhi | 15000 | | 1 | Ramesh | 32 | Ahmedabad | 20000 | +----+----------+-----+-----------+--------+ Fetched 6 row(s) in 0.54s
網(wǎng)站題目:創(chuàng)新互聯(lián)impala教程:impala ORDER BY子句
文章轉(zhuǎn)載:http://fisionsoft.com.cn/article/cdoisii.html


咨詢
建站咨詢
