if exists (select b1 from b group by b1 having count(1)>1) select * from a inner join b on a.a2=b.b2 else select * from a inner join b on a.a3=b.b3 从搂主描述出发,没明白为什么这样查
select * from A inner join B on A.a2=B.b2 where B.b1 in(select b1 from B group by b1 having count(*)>1) union all select * from A inner join B on A.a2=B.b2 where B.b1 in(select b1 from B group by b1 having count(*)=1)
--修改 select * from A inner join B on A.a2=B.b2 where B.b1 in(select b1 from B group by b1 having count(*)>1) union all select * from A inner join B on A.a3=B.b3 where B.b1 in(select b1 from B group by b1 having count(*)=1)
select * from a inner join b on a.a2=b.b2
else
select * from a inner join b on a.a3=b.b3
从搂主描述出发,没明白为什么这样查
where B.b1 in(select b1 from B group by b1 having count(*)>1)
union all
select * from A inner join B on A.a2=B.b2
where B.b1 in(select b1 from B group by b1 having count(*)=1)
--修改
select * from A inner join B on A.a2=B.b2
where B.b1 in(select b1 from B group by b1 having count(*)>1)
union all
select * from A inner join B on A.a3=B.b3
where B.b1 in(select b1 from B group by b1 having count(*)=1)