日期:2014-05-18 浏览次数:20565 次
select (select E from Y where D=a.A) as A, (select E from Y where D=a.B) as B, (select E from Y where D=a.C) as D from X as a
------解决方案--------------------
create table #A(A VARCHAR(10),B VARCHAR(10),C VARCHAR(10)) create table #B(D VARCHAR(10),E VARCHAR(10)) INSERT #A SELECT '1','3','5' UNION ALL SELECT '2','4','6' INSERT #B SELECT 1,'语文' union all select 2,'数学' union all select 3,'英语' union all select 4,'化学' union all select 5,'物理' union all select 6,'生物' select b.E A,c.E B,d.E C from #A a left join #B b on a.A=b.D left join #B c on a.B=c.D left join #B d on a.C=d.D
------解决方案--------------------
go create table X( A int, B int, C int ) go insert X select 1, 3 ,5 union all select 2, 4 ,6 go create table Y( D int, E varchar(10) ) go insert Y select 1 ,'语文' union all select 2 ,'数学' union all select 3 ,'英文' union all select 4 ,'化学' union all select 5 ,'物理' union all select 6 ,'生物' select b.E A,c.E B,d.E C from X a left join Y b on a.A=b.D left join Y c on a.B=c.D left join Y d on a.C=d.D /* A B C 语文 英文 物理 数学 化学 生物 */