我有一个名为Ratings
columns User_No
、Recipe_No
和Rating
插入后,我想更新Avg_Rating
另一个名为Recipes
.
我是 SQL 语法的新手,但这基本上是我想要做的
CREATE TRIGGER `Update_Avg` AFTER INSERT ON `Ratings`
FOR EACH ROW
SELECT @recipeNo = Recipe_No FROM INSERTED;
SELECT @avg = AVG(Rating) FROM databs.Ratings WHERE
`Recipe_No` = @recipeNo;
INSERT INTO databs.Recipes (`Avg_Rating`) VALUES (@avg)
WHERE `Recipe_No` = @recipeNo;