Oracle 分組聚合二種寫法,listagg和wmsys.wm_concat


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
select goodsid,listagg(ss.StorageNo,',')  within group (order by ss.StorageNo) StorageNo
      from StorageGoods ssg
      left join storage ss on ssg.storageid=ss.guid
      group by goodsid
select goodsid,wmsys.wm_concat(ss.StorageNo) StorageNo
      from StorageGoods ssg
      left join storage ss on ssg.storageid=ss.guid
      --where ssg.goodsid=sd.goodsid
      group by goodsid

 另參考:http://dacoolbaby.iteye.com/blog/1698957


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM