我有两个表流体和cas,我试图用cad表的平均分数更新相关的表液。像这样:
UPDATE fluids INNER JOIN cas on cas.cas = fluids.cas
SET fluids.score = avg(cas.score) GROUP BY cas.cas
答案 0 :(得分:1)
您需要将聚合选择包装为子查询:
UPDATE fluids
INNER JOIN (
SELECT cas,avg(cas.score) as avg_score
FROM cas
GROUP BY cas
) as c ON c.cas = fluids.cas
SET fluids.score = c.avg_score