我有一个名为Ratings
的表格,其中列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;