我有一个名称在一列中的数据集以及其他几列。我想显示字段中所有其他值相同的位置,连接名称。
e.g。
col 1 col 2 col 3
a 1 mary
a 1 jane
a 1 kevin
b 2 mary
b 2 jane
b 2 kevin
c 3 mary
c 3 jane
c 3 kevin
输出为:
a 1 mary, jane, kevin
b 2 mary, jane, kevin
c 3 mary, jane, kevin
我尝试过使用rtrim,但它没有做任何事情。我也尝试过使用listagg,但是我收到错误'Not a group by expression'
所有字段都是字符串,不可计算。
TIA
答案 0 :(得分:3)
详情here
select col1,
col2,
listagg(col3, -- The aggregated column
',') -- The delimiter
within group -- Because this is an aggregated function, needs to be grouped
(order by Col3) -- We can order the aggregated values
as Col3 -- And an alias for good measure
from TableA
group by col1, col2