首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

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

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

求:在同一张表中根据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 dualunion allselect 2,'a','world' from dualunion allselect 3,'a','haha' from dualunion allselect 4,'b','ccc' from dualunion allselect 5,'b','ddd' from dual)select     name,replace(wm_concat(text),',','') from t     group by name;NAME REPLACE(WM_CONCAT(TEXT),',',''---- --------------------------------------------a    helloworldhahab    cccddd 

热点排行