27,579
社区成员
发帖
与我相关
我的任务
分享
set nocount on
if object_id('T1')is not null drop table T1
go
create table T1(ID varchar(5), INTA int, SIGN varchar(5))
insert T1 select 'AA' , 100, ''
insert T1 select 'BB' , 200 , ''
insert T1 select 'AA', 300 , ''
insert T1 select 'CC', 100 ,''
if object_id('T2')is not null drop table T2
go
create table T2(ID varchar(5), INTA int, SIGN varchar(5))
insert T2 select 'AA' ,200,''
insert T2 select 'BB' ,100 ,''
insert T2 select 'CC' , 200 ,''
insert T2 select 'AA', 300 ,''
update T1 set sign='值' from (select id,sum(inta)inta from T1 group by ID)a,(select id,sum(inta)inta from T2 group by ID)b --更新T1 的Sgin 更新T2同理
where a.inta>b.inta and a.id=b.id and a.id=T1.id
select * from T1
/*ID INTA SIGN
----- ----------- -----
AA 100
BB 200 值
AA 300
CC 100 */