参见英文答案 >
LISTAGG in oracle to return distinct values13个答案我有一个这样的表:
group_id name -------- ---- 1 David 1 John 1 Alan 1 David 2 Julie 2 Charles
我想要以下结果:
group_id names -------- ----- 1 'Alan,David,John' 2 'Charles,Julie'
我可以使用下面的查询:
select group_id,listagg(name,',') within group (order by name) as names from demotable group by group_id
得到这个(非常类似的结果):
group_id names -------- ----- 1 'Alan,Julie'
我今天没有11g的实例可用,但你不能使用:
原文链接:https://www.f2er.com/oracle/206682.htmlSELECT group_id,LISTAGG(name,') WITHIN GROUP (ORDER BY name) AS names FROM ( SELECT UNIQUE group_id,name FROM demotable ) GROUP BY group_id