首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

简单有关问题,解决给分

2012-02-02 
简单问题,急,解决给分.t1aabbcc123224t2aaa13t3aabbccaaa12312243表没关联字段.[解决办法]select a.*,aaa

简单问题,急,解决给分.
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

热点排行