SELECT gameratingstblx245v.gameid,avg( gameratingstblx245v.rating ) as avgrating, count(gameratingstblx245v.rating) as count,gamedata.name ,gamedata.gameinfo
FROM gameratingstblx245v
LEFT JOIN gamedata ON gamedata.id = gameratingstblx245v.game_id
WHERE gameratingstblx245v.game_id=gameratingstblx245v.game_id
GROUP BY gameid
ORDER BY avg( gameratingstblx245v.rating ) DESC LIMIT 0,8
表 gameratingstblx245v - gameid ,评分
Rable gamedata - id ,gameinfo,name,releasedate
这是我目前用于从两个表gamedata和gameratingstblx245v中提取数据的查询....我在这里做的是采取平均值。表gameratingstblx245v中所有评分的平均降序排列我还从表游戏数据中提取与所选游戏人物相对应的相关信息......
现在我要提取的是最高平均值。来自game_ratingstblx245v的评分,但是对于那些从桌面游戏数据发布的游戏是在过去的90天... 帮助将不胜感激。谢谢。
答案 0 :(得分:6)
以下是我设计该查询的方式:
SELECT d.id, d.name, d.gameinfo,
AVG(r.rating) AS avgrating, COUNT(r.rating) AS count
FROM gamedata d
LEFT JOIN gameratingstblx245v r ON (d.id = r.game_id)
WHERE d.releasedate BETWEEN NOW() - INTERVAL 90 DAY AND NOW()
GROUP BY d.id
ORDER BY avgrating DESC LIMIT 0,8;