求一条合并记录的sql语句

gd4134 2006-04-29 11:33:13
例:
table1
A B
1 a
2 b
3 c
4 d
5 e

table2
C D
6 f
7 g
8 h
9 i
10 j

结果
A B C D
1 a 6 f
2 b 7 g
3 c 8 h
4 d 9 i
5 e 10 j
...全文
236 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangpei2008 2006-04-29
  • 打赏
  • 举报
回复
对不起,看错了
xeqtr1982 2006-04-29
  • 打赏
  • 举报
回复
declare @t table(a int,b varchar(10))
insert into @t select 1,'a'
union all select 2,'b'
union all select 3,'c'
union all select 4,'d'
union all select 5,'e'

declare @a table(c int,d varchar(10))
insert into @a select 6,'f'
union all select 7,'g'
union all select 8,'h'
union all select 9,'i'
union all select 10,'j'

select [id]=identity(int,1,1),* into # from @t
select [id]=identity(int,1,1),* into #1 from @a

select a.a,a.b,b.c,b.d from # a,#1 b where a.id=b.id

drop table #,#1
wwh999 2006-04-29
  • 打赏
  • 举报
回复
好像是笛卡爾...
select a.*,b.* from a,b
itblog 2006-04-29
  • 打赏
  • 举报
回复
select * from table1 t1 inner join table2 t2 on t1.A+5=t2.C
liangpei2008 2006-04-29
  • 打赏
  • 举报
回复
select t1.a,t1.b,t2.c,t2.d
from table1 t1,table2 t2
dulei115 2006-04-29
  • 打赏
  • 举报
回复
select a.*, b.*
from table1 a join table2 b on a.a = b.c - 5

????

34,837

社区成员

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

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