请教高手:
现在有两个表,结构如下:
表1
人员1 人员2 人员3
张三 李四 王五表2
编号 人员
001 张三
002 李四
003 王五现在想用一条SQL语句得到表3如下
表3
人员1 人员2 人员3
001 002 003在线等,急急急!
现在有两个表,结构如下:
表1
人员1 人员2 人员3
张三 李四 王五表2
编号 人员
001 张三
002 李四
003 王五现在想用一条SQL语句得到表3如下
表3
人员1 人员2 人员3
001 002 003在线等,急急急!
(select 编号 from 表2 c where a.人员2=c.人员) as 人员2,
(select 编号 from 表2 d where a.人员3=d.人员) as 人员3
from 表1 a
select 人员1=(select 编号 from 表2 where 人员=a.人员1),
人员2=(select 编号 from 表2 where 人员=a.人员2),
人员3=(select 编号 from 表2 where 人员=a.人员3)
from 表1 a
insert 表1
select N'张三',N'李四',N'王五'create table 表2(编号 varchar(10),人员 varchar(10))
insert 表2
select '001',N'张三' union
select '002',N'李四' union
select '003',N'王五'select 人员1=(select 编号 from 表2 where 人员=a.人员1),
人员2=(select 编号 from 表2 where 人员=a.人员2),
人员3=(select 编号 from 表2 where 人员=a.人员3)
from 表1 adrop table 表1
drop table 表2
from
(select 编号 from 表1 t ,表2 where 人员=t.人员1) a
,(select 编号 from 表1 t ,表2 where 人员=t.人员2) b
,(select 编号 from 表1 t ,表2 where 人员=t.人员3) c