表A:
ID Name Mark
1001 张三 uu
1002 李四 pp
1003 王五 kk
表B:
beingTracked tracked
1001 1002
1001 1003
最后要查询得到:
ID Name Mark 合并
1001 张三 uu (1002 李四 pp),(1003 王五 kk)
------解决方案--------------------
with a as(
select '1001' id,'张三' name, 'uu' mark from dual union all
select '1001' id,'张三' name, 'uu' mark from dual union all
select '1002','李四','pp' from dual union all
select '1003','王五','kk' from dual),
b as(
select '1001' beingTracked,'1002' tracked from dual union all
select '1001','1003' from dual)
select a.id,
a.name,
a.mark,
beingTracked,
wmsys.wm_concat(distinct c.tracked) 合并
from (select beingTracked,
(select id
------解决方案--------------------
' '
------解决方案--------------------
name
------解决方案--------------------
' '
------解决方案--------------------
mark
from a
where a.id = b.tracked) tracked
from b) c,
a
where c.beingTracked = a.id
group by a.id, a.name, a.mark, beingTracked
------解决方案--------------------
看都没人给你回了:我来给个结果吧,我自测的,你研究下
create table TESTA
(
id NUMBER not null,
name VARCHAR2(10),
mark VARCHAR2(10)
);
insert into TESTA (id, name, mark)
values (1001, 'jam', 'ui');
insert into TESTA (id, name, mark)
values (1002, 'jack', 'kk');
insert into TESTA (id, name, mark)