[英]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.