请教一个相对比较麻烦的查询
WeiWY 2020-05-16 09:29:31 已知有两个表:
drop table if exists aa
create table aa(a int)
insert into aa(a)
select 1 union all
select 2 union all
select 3
drop table if exists aa
create table bb(b1 varchar(10),b2 int)
insert into bb(b1,b2)
select 'a',1 union all
select 'a',2 union all
select 'a',3 union all
select 'b',1 union all
select 'b',2 union all
select 'c',1 union all
select 'c',3
想达到下面的查询效果,其中,1,2,3是表格aa中的所有数据,需要随着表格中的数据变化而变化,请问该如何查询
select b1 from bb where b2 = 1
InterSect
select b1 from bb where b2 = 2
InterSect
select b1 from bb where b2 = 3