簡體   English   中英

oracle與listagg不同

[英]oracle distinct with listagg

我有桌子 我可以在同一行中使用“,”顯示表中列的所有數據。 但我不能明確地應用它。 請幫忙

這很棘手。 一個簡單的建議是使用select distinct

select listagg(col, ',') within group (order by col)
from (select distinct col from t) x;

但是,這使得難以計算其他聚合(或生成比listagg()結果更多的聚合)。 另一種方法是將窗口函數與listagg()結合使用:

select listagg(case when seqnum = 1 then col end, ',') within group (order by col)
from (select t.*,
             row_number() over (partition by col order by col) as seqnum
      from t
     ) t

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM