17,082
社区成员
发帖
与我相关
我的任务
分享
create table test1(id1 int,id2 int,col1 int,col2 int);
create table test2(id1 int,id2 int,v1 int,v2 int);
insert into test1(id1,id2,col1,col2)values(11,12,1001,1002);
insert into test1(id1,id2,col1,col2)values(13,14,1003,1004);
insert into test1(id1,id2,col1,col2)values(15,16,1005,1006);
insert into test2(id1,id2,v1,v2) values(21,22,2001,2002);
insert into test2(id1,id2,v1,v2) values(23,24,2003,2004);
insert into test2(id1,id2,v1,v2) values(25,26,2005,2006);
insert into test2(id1,id2,v1,v2) values(27,28,2007,2008);
update(
select t1.col1,tt.v1 from test1 t1,
( select id1,id2,max(v1)v1 from test2 t2
group by id1,id2
)tt where t1.id1=tt.id1 and t1.id2=tt.id2
)t set t.col1=t.v1;