我正在尝试使用LISTAGG
Oracle中的函数。我想只获得该列的不同值。有没有一种方法可以在不创建函数或过程的情况下获得唯一的值?
col1 col2 Created_by
1 2 Smith
1 2 John
1 3 Ajay
1 4 Ram
1 5 Jack
我需要选择col1和LISTAGG
col2(不考虑第3列)。当我这样做时,我得到如下结果LISTAGG
:[2,2,3,4,5]
我需要在这里删除重复的'2'; 我只需要col1与col1不同的值。
发布于 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;
https://stackoverflow.com/questions/-100007716
复制相似问题