17,377
社区成员
发帖
与我相关
我的任务
分享
select
id,decode(mm,1,name,'')name,decode(mm,1,class,'')class,(case when ll<=mm then sex else '' end) sex
from
(
select id,name,class,sex,nn,
row_number() over(partition by id,nn order by id) ll,mm
from
(
select a.id id,name,class,sex,nn,row_number() over(partition by name,class order by id) mm from a left outer join b on a.id = b.id
full join (select c.*,row_number() over(partition by c.id order by c.id)nn from c )c on a.id=c.id order by a.id)
)
--result:
1 tom F
2 cat a1 M
2 cat c3
3 nick
4 lucy d2 F
4 F
select a.id, a.name, b.class, c.sex
from a
left outer join b on a.id = b.id
left outer join c on a.id = c.id