我需要一个查询,它会更新Games
中的一行,使其记录的Ratings
的平均值乘以它所拥有的Plays
的数量。这是我到目前为止所做的,但它似乎没有起作用:
UPDATE Games
SET PlaysRating = ROUND(AVG
(SELECT `Rating` FROM GameRatings WHERE GameID = '37')
* (SELECT COUNT(*) FROM Plays WHERE GameID = '37'))
WHERE ID = 37
答案 0 :(得分:3)
看起来像这样:
UPDATE Games
SET PlaysRating = round(
(SELECT count(*) FROM Plays WHERE GameID = 37)
* (SELECT avg(Rating) FROM GameRatings WHERE GameID = 37))
WHERE ID = 37
BTW,假设ID是数字类型,我删除了引号''
。