我有一个包含值的表:
ID | 类型 | 文本 |
---|---|---|
1 | 注释用户注释1 | |
2 | 备注 | 用户备注|
3 | 注释 | 用户注释2|
4 | 注释 | 用户注释3 |
5 | 备注 | 由adm备注
一个选项是使用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;在这里摆弄