日期:2014-05-17 浏览次数:20421 次
update a set heji=b.zuoyeliang from a join (select zyhao,sum(zuoyeliang) as zuoyeliang from b group b y zyhao) on a.zyhao=b.zyhao
------解决方案--------------------
update 表A set heji=b.zuoyeliang from 表A a inner join (select zyhao,sum(zuoyeliang) as zuoyeliang from 表B group by zyhao) b on a.zyhao=b.zyhao
------解决方案--------------------
--1 SELECT B.zyhao , SUM(zuoyeliang) FROM B WHERE EXISTS ( SELECT 1 FROM A WHERE zyhao = B.zyhao ) GROUP BY B.zyhao --2 UPDATE A SET A.heji = T.heji FROM ( SELECT B.zyhao , SUM(zuoyeliang) AS heji FROM B WHERE EXISTS ( SELECT 1 FROM A WHERE zyhao = B.zyhao ) GROUP BY B.zyhao ) T WHERE A.zyhao = T.zyhao