如何在一个表中将多行合并为一行

时间:2013-07-24 15:34:07

标签: sql oracle11g

表名称为NOTES, 列NAMES = ID,日期,代码,文本

ID   DATE           CODE     TEXT
1    7/24/2013       CD1     HELLO

1    7/24/2013       CD1     STACK OVER FLOW

2    1/24/2000       CD2     PLEASE HELP ME 

2    1/24/2000       CD2     THANK YOU 

2    1/24/2000       CD2     VERY MUCH

我的要求:oracle SQL LOGIC

ID   DATE           CODE     TEXT

1    7/24/2013       CD1     HELLO, STACK OVER FLOW

2    1/24/2000       CD2     PLEASE HELP ME, THANK YOU, VERY MUCH  

1 个答案:

答案 0 :(得分:2)

尝试

SELECT 
ID,
DATE,
CODE,
LISTAGG(TEXT, ',') WITHIN GROUP (ORDER BY CODE)
FROM NAMES
GROUP BY ID, DATE, CODE