34,588
社区成员
发帖
与我相关
我的任务
分享
select *
from a a
inner join b b
on a.a1=b.b1
inner join b c
on a.a2=c.b1
where 你的条件
其实都一样 你自己改改就可以了 select * from a1 a inner join b1 b on a.a1=b.b1 and a.a2=b.b1
create table testa(name varchar(10),a1 int,a2 int)
insert testa
select '张三',1,3 union all
select '李四',2,4
create table testb(b1 int,bname nvarchar(10))
insert testb
select 1,'Xxx单位' union all
select 2,'yyy单位' union all
select 3,'管理部' union all
select 4,'宣传部'
select 名字=a.name,
单位=b.bname,
部门=c.bname
from testa a
inner join testb b
on a.a1=b.b1
inner join testb c
on a.a2=c.b1
/*
名字 单位 部门
张三 Xxx单位 管理部
李四 yyy单位 宣传部
*/