日期:2014-05-17 浏览次数:20581 次
;
WITH t2
AS ( SELECT id ,
SUM(quantity) quantity
FROM t2
GROUP BY id
)
UPDATE t1
SET t1.number = t2.quantity
FROM t1
INNER JOIN t2 ON t1.id = t2.ID
--2000的写法
UPDATE t1
SET t1.number = t2.quantity
FROM t1
INNER JOIN ( SELECT id ,
SUM(quantity) quantity
FROM t2
GROUP BY id
) t2 ON t1.id = t2.ID