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

你可能感兴趣的:(Oracle)