如何根据Oracle SQL中的条件将值连接到一个单元格中



我有一个包含值的表:

用户备注用户注释2由adm备注
ID 类型 文本
1 注释用户注释1
2 备注
3 注释
4 注释 用户注释3
5 备注

一个选项是使用listagg

with x ( id, category, comments )as 
(
select 1 , 'note'   , 'note by user1'   from dual union all
select 2 , 'remark' , 'remark by user'  from dual union all
select 3 , 'note'   , 'note by user2'   from dual union all
select 4 , 'note'   , 'note by user 3'  from dual union all
select 5 , 'remark' , 'remark by adm'   from dual 
)
select category, listagg(comments,';' ) within group (order by id)
from x 
group by category ;

db<gt;在这里摆弄

相关内容

最新更新