2
我有2个表,Ratings
和Recipes
。MySQL插入后触发更新行,其中
在插入Ratings
后,我需要查找额定配方的所有评级的平均值,并更新Recipes
表中的Rating_Avg
列。
这个工程,但我相信它是更新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
,但我不知道在哪里添加。
谢谢,我想我是在正确的轨道哈哈 – chuckieDub 2013-03-22 04:52:37