有一张表: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)来做到?
1 a hello
2 a world
3 a haha
4 b ccc
5 b ddd我想根据name字段,如果同名就显示:a helloworldhaha
b ccdd怎么用一条SQL语句(不用store procedure)来做到?
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
如果我的表名叫sp,你的那段SQL因该怎么写啊?还望指教。
不知道还有没有其它办法来拼这个字符串呢?
select 表.name,listagg(表.text),'') within group (order by 表.name) from 表 group by 表.name;