示例:A表为详情记录表,B表为统计表。将A表中获得的统计值更新至B表。
SQL如下:
UPDATE table_a a
JOIN (
SELECT COUNT(*) AS total, AVG(col) AS avg FROM table_b WHERE xxx
) AS t
SET a.col_1 = t.total, a.col_2 = t.avg WHERE xxx
示例:A表为详情记录表,B表为统计表。将A表中获得的统计值更新至B表。
SQL如下:
UPDATE table_a a
JOIN (
SELECT COUNT(*) AS total, AVG(col) AS avg FROM table_b WHERE xxx
) AS t
SET a.col_1 = t.total, a.col_2 = t.avg WHERE xxx