這篇文章主要介紹Oracle中l(wèi)istagg函數(shù)的使用方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
青島網(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)站的公司定做!
listagg函數(shù)的用法
這是一個(gè)Oracle的列轉(zhuǎn)行函數(shù):LISTAGG()
先看示例代碼:
Sql代碼
with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Shanghai' city from dual union all select 'China' nation ,'Beijing' city from dual union all select 'USA' nation ,'New York' city from dual union all select 'USA' nation ,'Bostom' city from dual union all select 'Japan' nation ,'Tokyo' city from dual ) select nation,listagg(city,',') within GROUP (order by city) from temp group by nation
這是最基礎(chǔ)的用法:
LISTAGG(XXX,XXX) WITHIN GROUP( ORDER BY XXX)
用法就像聚合函數(shù)一樣,通過(guò)Group by語(yǔ)句,把每個(gè)Group的一個(gè)字段,拼接起來(lái)。
非常方便。
同樣是聚合函數(shù),還有一個(gè)高級(jí)用法:
就是over(partition by XXX)
也就是說(shuō),在你不實(shí)用Group by語(yǔ)句時(shí)候,也可以使用LISTAGG函數(shù):
Sql代碼
with temp as( select 500 population, 'China' nation ,'Guangzhou' city from dual union all select 1500 population, 'China' nation ,'Shanghai' city from dual union all select 500 population, 'China' nation ,'Beijing' city from dual union all select 1000 population, 'USA' nation ,'New York' city from dual union all select 500 population, 'USA' nation ,'Bostom' city from dual union all select 500 population, 'Japan' nation ,'Tokyo' city from dual ) select population, nation, city, listagg(city,',') within GROUP (order by city) over (partition by nation) rank from temp
以上是“Oracle中l(wèi)istagg函數(shù)的使用方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!