首页新闻找找看学习计划

请教一个SQL更新语句,麻烦高手看看怎么写……

0
悬赏园豆:10 [已解决问题] 解决于 2013-01-24 08:46
create table a(id int ,name nvarchar(20))
create table b(id int ,name nvarchar(20))
go
insert A values(1,'A')
insert A values(3,'AAA')
insert A values(5,'AAAAA')
insert B values(2,'BB')
insert B values(4,'BBBB')
insert B values(6,'BBBBBB')

有以上2张表,现在要按照下图中条件来更新……

哪位知道怎么写呢?谢谢!

hexllo的主页 hexllo | 菜鸟二级 | 园豆:405
提问于:2012-12-22 13:57
< >
分享
最佳答案
1

with ta as(    
select aa.id,aa.name,aa.rid, convert(nvarchar(10),bb.id)+bb.name as t from
(select *, row_number() over(order by id) rid from a) aa
inner join
(select *, row_number() over(order by id) rid from b) bb
on aa.rid = bb.rid
)  
update a set a.name = ta.t from a,ta where a.id = ta.id

hexllo | 菜鸟二级 |园豆:405 | 2012-12-22 15:55

楼上正解

edsonwu | 园豆:146 (初学一级) | 2013-01-11 14:14
其他回答(3)
0

UPDATE a SET a.name =CONVERT(nvarchar(50), b.id)+b.name  FROM a  left join b on a.rid=b.id

 

A表

1 1BB 1
3 2BBBB 2
5 3BBBBBB 3

 

B表

1 BB
2 BBBB
3 BBBBBB

收获园豆:2
chennie | 园豆:209 (菜鸟二级) | 2012-12-22 14:25
0

insert into a(name) values((select id from b)+(select name from b))

光头之雨男 | 园豆:196 (初学一级) | 2012-12-22 14:30
0

inner join 啊 

类似这样的语句:

select ROW_NUMBER() OVER( ORDER BY PSIO.CreateTime DESC ) AS RowNumber,PSIO.SeqNo,PSIO.CreateTime from dbo.Output PSIO 
inner join Album PPA on PSIO.PPAID=PPA.PPAID 
where PPA.PPAID=103

收获园豆:8
chenping2008 | 园豆:9836 (大侠五级) | 2012-12-22 14:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册