日期:2014-05-17 浏览次数:20431 次
CREATE TABLE testA (NAME VARCHAR(10), [money]int ) INSERT INTO testA SELECT 'b001', 0 UNION ALL SELECT 'b002', 0 UNION ALL SELECT 'b003', 0 UNION ALL SELECT 'b004', 0 CREATE TABLE testB (NAME VARCHAR(10), [money]int) INSERT INTO testB SELECT 'b001', 10 UNION ALL SELECT 'b001', 20 UNION ALL SELECT 'b001', 10 UNION ALL SELECT 'b002', 100 UNION ALL SELECT 'b003', 100 WITH cte AS ( SELECT NAME,SUM(money) [money] FROM testB GROUP BY NAME) UPDATE a SET a.[money]=b.[money] FROM testA a INNER JOIN cte B ON a.NAME=b.NAME SELECT * FROM testA /* (3 行受影响) NAME money ---------- ----------- b001 40 b002 100 b003 100 b004 0 (4 行受影响) */