ORACLE 新手求助 查询结果表按照分号分隔开并分组问题
请教各位大仙
oracle查询结果表中有三列数据
列一 列二 列三
11 22 A1
11 22 A2
11 22 A3
请问如何将列三 中的数据 A1,A2,A3按照分号分割开
并按照列一,列二分组 显示成一行
如 11 22 A1,A2,A3 这种形式
[最优解释]
with t(col1,col2,col3) as(
select 11,22,'A1' from dual
union all select 11,22,'A2' from dual
union all select 11,22,'A3' from dual
)
select col1,col2,wm_concat(col3) col3 from t group by col1,col2;
--wm_concat排序是很乱的,如果需要指定排序,如
with t(col1,col2,col3) as(
select 11,22,'A1' from dual
union all select 11,22,'A2' from dual
union all select 11,22,'A3' from dual
)
select col1,col2,max(col3) col3
from (select col1,col2,wm_concat(col3) over (partition by col1,col2 order by col3) col3 from t)
group by col1,col2;