请教一个相对比较麻烦的查询

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
...全文
54 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧