注意: 上面的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;
你这样写应该不妥吧 表2有上万条以上(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) 按你这样不是要写............
我都告诉你了上面是我的测试数据,你不用管的,只需要用下面的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;
上面的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;
表2有上万条以上(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) 按你这样不是要写............
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;