0

我有一个名为Ratingscolumns User_NoRecipe_NoRating

插入后,我想更新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; 
4

0 回答 0