示例场景
两个表 ordrs, sum_orders, sum_orders 中的count是 orders中相同project_id的count之和;cost同理
一条语句直接更新sum_orders中的count & cost
#orders
#sum_orders
示例代码
UPDATE sum_orders a INNER JOIN ( SELECT project_id, sum( count ) AS sum_count, sum( cost ) AS sum_cost FROM orders GROUP BY project_id ) b ON a.project_id = b.project_id SET a.count = b.sum_count, a.cost = b.sum_cost;