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张表,现在要按照下图中条件来更新……
哪位知道怎么写呢?谢谢!
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
楼上正解
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
insert into a(name) values((select id from b)+(select name from b))
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