日期:2014-05-17  浏览次数:20621 次

求:在同一张表中根据name相同,把后面的text字段全部串成一个文件的SQL
有一张表:

no name text
1 a hello
2 a world
3 a haha
4 b ccc
5 b ddd

我想根据name字段,如果同名就显示:

a helloworldhaha
b ccdd

怎么用一条SQL语句(不用store procedure)来做到?

------解决方案--------------------
SQL code

with t as(
select 1 id,'a' name,'hello' text from dual
union all
select 2,'a','world' from dual
union all
select 3,'a','haha' from dual
union all
select 4,'b','ccc' from dual
union all
select 5,'b','ddd' from dual
)select 
    name,replace(wm_concat(text),',','')
 from t 
    group by name;


NAME REPLACE(WM_CONCAT(TEXT),',',''
---- --------------------------------------------
a    helloworldhaha
b    cccddd