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

yeeyee 2007-01-10 10:16:41
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

表没关联字段.
...全文
183 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yeeyee 2007-01-10
  • 打赏
  • 举报
回复
我帮我同学问的,解决了,谢谢了.
fish_yht 2007-01-10
  • 打赏
  • 举报
回复
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
caixia615 2007-01-10
  • 打赏
  • 举报
回复
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 行)
xiequanqin 2007-01-10
  • 打赏
  • 举报
回复
那就给他+一个关联列

可以分别都SELECT INTO 临时表(加个Identi字段),再根据这个JOIN
baggio328 2007-01-10
  • 打赏
  • 举报
回复
我晕,慢了这么多
baggio328 2007-01-10
  • 打赏
  • 举报
回复
select
aa=(select aa from t1),
bb=(select bb from t1),
cc=(select cc from t1),
aaa=(select aaa from t2)
yczealot 2007-01-10
  • 打赏
  • 举报
回复
在t1,t2中都加入一个标识列,用标识列进行关联即可,前提是两表记录条数相等
gc_ding 2007-01-10
  • 打赏
  • 举报
回复
select * from t1,t2
akuzou 2007-01-10
  • 打赏
  • 举报
回复
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
marco08 2007-01-10
  • 打赏
  • 举报
回复
--try

select
aa=(select aa from t1),
bb=(select bb from t1),
cc=(select cc from t1),
aaa=(select aaa from t2)
caixia615 2007-01-10
  • 打赏
  • 举报
回复
select a.*,aaa=(select aaa from t2) from t1 a
caixia615 2007-01-10
  • 打赏
  • 举报
回复
select a.*,aaa=(select aaa from t2) from t1

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧