我有 2 张桌子,Ratings并且Recipes.
插入后,Ratings我需要找到额定配方的所有评分的平均值,并更新表Rating_Avg中的列Recipes。
这可行,但我相信Recipes.Rating_Avg当我只需要更新Recipe_No =最近评级Recipe_No的行时,它会更新所有行。
CREATE TRIGGER `update_avg` AFTER INSERT ON `Ratings`
FOR EACH ROW UPDATE Recipes
SET Rating_Avg = (SELECT AVG(Rating) from Ratings where Ratings.Recipe_No=Recipes.Recipe_No)
我觉得我需要添加一个WHERE Recipe_No = NEW.Recipe_No,但我不确定在哪里添加它。