Oracle 将表中多条记录的同一字段汇总输出

记忆力不大好,随手贴一个帖子记录一下

假设有如下的一张表table1,如果想把carlie按照用户名汇总输出,那么SQL如下


select  Name,temp.car

from table1, (select name, WMSYS.WM_CONCAT(to_char(car)) car from table1 group by name) temp

where name = temp.name;

输出效果如下:

amy | x1,x5,x6

lulu   | x1,x3


table1

ID Name mail car
1 amy [email protected]

x1

2 amy [email protected] x5
3 amy [email protected] x6
4 lulu [email protected] x1
5 lulu [email protected] x3

你可能感兴趣的:(Oracle 将表中多条记录的同一字段汇总输出)