select a.a1,a.a2,a.a3,a.a4,a.a5,b.b6 from a,b where a.id = b.id
楼主看一下这个行不行~~~原帖:http://community.csdn.net/Expert/topic/5040/5040651.xml?temp=.6692316create table test1(ID int identity(1,1),字段1 char(1),字段2 char(1),字段3 char(1),字段4 char(1)) insert test1(字段1,字段2,字段3,字段4) select 'A','D','C','A' union all select 'A','A','D','C' union all select 'B','C','B','A' union all select 'C','B','A','B' union all select 'A','C','B','A' union all select 'D','A','B','A' select * from test1create table test2(字段1 char(1),字段2 int) insert test2 select 'A',5 union all select 'B',4 union all select 'C',3 union all select 'D',2 --select * from test2select sum(a.字段2) as 字段1, sum(b.字段2) as 字段1, sum(c.字段2) as 字段1, sum(d.字段2) as 字段1 from test1 i,test2 a,test2 b,test2 c,test2 d where i.字段1=a.字段1 and i.字段2=b.字段1 and i.字段3=c.字段1 and i.字段4=d.字段1drop table test1,test2
where a.id = b.id
insert test1(字段1,字段2,字段3,字段4)
select 'A','D','C','A' union all
select 'A','A','D','C' union all
select 'B','C','B','A' union all
select 'C','B','A','B' union all
select 'A','C','B','A' union all
select 'D','A','B','A'
select * from test1create table test2(字段1 char(1),字段2 int)
insert test2
select 'A',5 union all
select 'B',4 union all
select 'C',3 union all
select 'D',2
--select * from test2select
sum(a.字段2) as 字段1,
sum(b.字段2) as 字段1,
sum(c.字段2) as 字段1,
sum(d.字段2) as 字段1
from test1 i,test2 a,test2 b,test2 c,test2 d
where i.字段1=a.字段1 and i.字段2=b.字段1 and i.字段3=c.字段1 and i.字段4=d.字段1drop table test1,test2