|
纯粹为了题目写的,用的fulljoin效率不高,在这个结果上不难写匹配条件。楼主可以试试
select id,listagg(matchstr,',') within group (order by id) str
from (
select id,item_id ,
listagg(idmatch,',') within group (order by idmatch) ,
listagg(matchvalue,',') within group (order by idmatch) matchstr
from (
select a.id,a.item_id,a1.id as idmatch,value matchvalue from a full join a1
on a.item_id = a1.id
union all
select a.id,a.item_id,a2.id as idmatch,value matchvalue from a full join a2
on a.item_id = a2.id
union all
select a.id,a.item_id,a3.id as idmatch,value matchvalue from a full join a3
on a.item_id = a3.id
)
group by id ,item_id
)
group by id |
|