首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >LISTAGG在oracle中返回不同的值怎么处理?

LISTAGG在oracle中返回不同的值怎么处理?
EN

Stack Overflow用户
提问于 2018-03-21 08:02:26
回答 2查看 0关注 0票数 0

我正在尝试使用LISTAGGOracle中的函数。我想只获得该列的不同值。有没有一种方法可以在不创建函数或过程的情况下获得唯一的值?

  col1 col2 Created_by
   1 2 Smith
   1 2 John 
   1 3 Ajay 
   1 4 Ram 
   1 5 Jack

我需要选择col1和LISTAGGcol2(不考虑第3列)。当我这样做时,我得到如下结果LISTAGG[2,2,3,4,5]

我需要在这里删除重复的'2'; 我只需要col1与col1不同的值。

EN

Stack Overflow用户

发布于 2018-03-21 16:20:01

你的意思是这样的:

select listagg(the_column, ',') within group (order by the_column)
from (
   select distinct the_column 
   from the_table
) t

如果需要更多的列,可能需要这样的内容:

select col1, listagg(col2, ',') within group (order by col2)
from (
  select col1, 
         col2,
         row_number() over (partition by col1, col2 order by col1) as rn
  from foo
  order by col1,col2
)
where rn = 1
group by col1;
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100007716

复制
相关文章

相似问题

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