select * from A left join ( select 1 as ktype,id,col1,col2,col3,coln from B union all select 2 as ktype,id,col1,col2,col3,coln from c ) t on a.type=t.ktype and a.id=t.id
-- 凑个人数,使用 case when 就可以判断一下 create table a(id int ,type int , name varchar(30) ) insert into a values (1,1,'aaa') insert into a values (2,2,'bbb') insert into a values (3,1,'ccc') insert into a values (4,2,'ddd')create table b(id int , b_m varchar(30)) insert into b values (1,'xxx') insert into b values (2,'yyy')create table c(id int , c_m varchar(30)) insert into c values(2,'bbbbbb') insert into c values(3,'ccccccc') insert into c values(4,'dddddddd')select a.id , a.type ,a.name , case when a.id = 1 then b.b_m else c.c_m end as dc from a left join b on a.id = b.id left join c on a.id = c.id
from A left join (
select 1 as ktype,id,col1,col2,col3,coln from B
union all
select 2 as ktype,id,col1,col2,col3,coln from c
) t on a.type=t.ktype and a.id=t.id
-- 凑个人数,使用 case when 就可以判断一下
create table a(id int ,type int , name varchar(30) )
insert into a values (1,1,'aaa')
insert into a values (2,2,'bbb')
insert into a values (3,1,'ccc')
insert into a values (4,2,'ddd')create table b(id int , b_m varchar(30))
insert into b values (1,'xxx')
insert into b values (2,'yyy')create table c(id int , c_m varchar(30))
insert into c values(2,'bbbbbb')
insert into c values(3,'ccccccc')
insert into c values(4,'dddddddd')select a.id , a.type ,a.name ,
case when a.id = 1 then b.b_m else c.c_m end as dc
from a
left join b on a.id = b.id
left join c on a.id = c.id