日期:2014-05-16 浏览次数:20624 次
select a.XXX,a.A1,a.A2,a.A3,
case when b.YYY is not null then b.MM
when c.ZZZ is not null then c.MM
else null end 'MM',
case when b.YYY is not null then b.NN
when c.ZZZ is not null then c.NN
else null end 'NN'
from 表A a
left join 表B b on a.XXX=b.YYY
left join 表C c on a.XXX=c.ZZZ
select XXX,A1,A2,A3, MM = case when A.XXX = B.YYY then B.MM when A.XXX = C.ZZZ then C.MM end,
NN = case when A.XXX = B.YYY then B.NN when A.XXX = C.ZZZ then C.NN end
from A left join B on A.XXX = B.YYY left join C on A.XXX = C.ZZZ