日期:2014-05-19  浏览次数:20564 次

简单问题,急,解决给分.
t1

aa         bb       cc
1           2         3
2           2         4

t2

aaa
1
3  

t3

aa         bb       cc       aaa
1           2         3           1
2           2         4           3  

表没关联字段.

------解决方案--------------------
select a.*,aaa=(select aaa from t2) from t1
------解决方案--------------------
select a.*,aaa=(select aaa from t2) from t1 a
------解决方案--------------------
--try

select
aa=(select aa from t1),
bb=(select bb from t1),
cc=(select cc from t1),
aaa=(select aaa from t2)

------解决方案--------------------
select id=identity(int,1,1),* into #t1 from t1 order by aa
select id=identity(int,1,1),* into #t2 from t2 order by aaa
select a.aa,a.bb,a.cc,b.aaa from #t1 a,#t2 b where a.id=b.id
------解决方案--------------------
select * from t1,t2
------解决方案--------------------
在t1,t2中都加入一个标识列,用标识列进行关联即可,前提是两表记录条数相等
------解决方案--------------------
select
aa=(select aa from t1),
bb=(select bb from t1),
cc=(select cc from t1),
aaa=(select aaa from t2)
------解决方案--------------------
我晕,慢了这么多
------解决方案--------------------
那就给他+一个关联列

可以分别都SELECT INTO 临时表(加个Identi字段),再根据这个JOIN
------解决方案--------------------
declare @a table(aa int,bb int,cc int)
insert into @a select 1,2,3 union all
select 2,2,4
declare @b table(aaa int)
insert into @b select 1 union all
select 3
select id1=identity(int,1,1),a.* into #a from @a a
select id2=identity(int,1,1),b.* into #b from @b b
select a.aa,a.bb,a.cc,b.aaa from #a a,#b b where a.id1=b.id2
drop table #a,#b
result:
aa bb cc aaa
----------- ----------- ----------- -----------
1 2 3 1
2 2 4 3

(所影响的行数为 2 行)

------解决方案--------------------
ls的方法可行
--------------------------
select identity(1,1) id,* into #aa from t1
select identity(1,1) id,* into #aaa from t2

select aa,bb,cc,aaa from #aa a inner join #aaa b on a.id = b.id