日期:2014-05-18 浏览次数:20541 次
update a set a.A3=b.B3 from A表 a join B表 b on a.A1=b.B1 -- 是用的a.A1=b.B1做为条件,看楼主是不是要这个条件。
------解决方案--------------------
update a set a.A3=b.B3 from A表 a join (select B2,sum(B3) from b group by b2) b on a.A2=b.B2
------解决方案--------------------
create table a(a1 int,a2 varchar(10),a3 int) insert into a select 1,'a',0 union all select 2,'b',0 create table b(b1 int,b2 varchar(10),b3 int) insert into b select 1,'a',10 union all select 2,'b',2 union all select 3,'b',1 update a set a.A3=(select sum(b.b3) from b where b.b2=a.a2) --drop table a --drop table b ------------------------ 1 a 10 2 b 3