首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >oracle distinct with listagg

oracle distinct with listagg
EN

Stack Overflow用户
提问于 2018-09-21 21:05:47
回答 1查看 799关注 0票数 0

我有一张桌子。我可以在同一行中使用',‘来显示表中某列的所有数据。但我不能明确地应用它。请给我hepl

EN

回答 1

Stack Overflow用户

发布于 2018-09-21 21:08:41

这很棘手。一个简单的建议是使用select distinct

代码语言:javascript
复制
select listagg(col, ',') within group (order by col)
from (select distinct col from t) x;

然而,这使得很难计算其他聚合(或者生成比listagg()结果更多的聚合)。另一种方法是将窗口函数与listagg()结合使用

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52444449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档