【发布时间】:2011-01-27 12:50:38
【问题描述】:
数据库:
player | team | points
player1 | team1 | 100
player2 | team1 | 90
player3 | team2 | 100
player4 | team2 | 95
player5 | team2 | 90
我试图从每支球队的积分中获得前 2 名球员,并将他们平均到球队排名中,同时在查询中对球队进行分组:
team2 97.5 (not 95)
team1 95
`$mysqli->query("SELECT charGuild, gr FROM (
SELECT charGuild, AVG(charRating) as gr
FROM ins_rated
GROUP BY charGuild
HAVING COUNT(*) >= 10
ORDER BY gr DESC
LIMIT 15
)
ORDER BY gr DESC
LIMIT 40");`
没有按预期工作。
$mysqli->query("SELECT charGuild, AVG(charRating) AS gr
FROM ins_rated
GROUP BY charGuild
HAVING COUNT(*) >= 10
ORDER BY gr DESC
LIMIT 40");
列出在数据库中至少有 10 人的顶级团队。现在添加一种仅让前 15 名球员平均球队得分的方法是我迷路的地方。
【问题讨论】:
-
@Martin 看起来它会完成工作,但它输出的是我已经可以实现的默认值。 IE。子选择中的过滤器什么也不做。