答案 0 :(得分:1)
如果您知道有三个值,则可以使用row_number()
:
select t.col1,
max(case when seqnum = 1 then col2 end) as col_a,
max(case when seqnum = 2 then col2 end) as col_b,
max(case when seqnum = 3 then col2 end) as col_c
from (select t.*, row_number() over (partition by col1 order by col2) as seqnum
from t
) t
group by t.col1;
答案 1 :(得分:1)
与前面提到的问题非常相似,你可以使用listagg和逗号分隔输出。
选择c1,
组内的listagg(c2,',')(按c2排序)为col2
从t1
c1组;
在liveSql中发布了测试脚本。 https://livesql.oracle.com/apex/livesql/s/gj16yorj8qd0r7mi7whowv89a