这样需要如何写sql
a表
列1,列2
1,55
2,80
b表
列1,列2
1,wss
1,三
2,四
2,千万
a表.列1 = b表.列1
想得到结果
1,55,wss 三
2,80,四 千万
------解决方案--------------------
你数据中加的逗号是什么意思?是数据中就有的逗号还是需要显示出逗号?
------解决方案--------------------
注意:
上面的t1和t2只是构建临时表,你只需要用下面的SQL即可,你可以直接将t1和t2直接替换成你的表
with t1 as
(select 1 c1, 55 c2 from dual union all select 2 c1, 80 c2 from dual),
t2 as
(select 1 c1, 'wss' c2
from dual
union all
select 1 c1, 'san'
from dual
union all
select 2 c1, 'si'
from dual
union all
select 2 c1, 'qianwang'
from dual)
select t1.c1, t1.c2, t3.c3
from t1,
(select c1, replace(to_char(wm_concat(c2)), ',', ' ') c3
from t2
group by c1) t3
where t1.c1 = t3.c1;
------解决方案--------------------
我都告诉你了上面是我的测试数据,你不用管的,只需要用下面的SQL:
t1 -> a
t2 -> b
select t1.c1, t1.c2, t3.c3
from t1,
(select c1, replace(to_char(wm_concat(c2)), ',', ' ') c3
from t2
group by c1) t3
where t1.c1 = t3.c1;