我想计算在给定日期之后总分至少为 300 的所有玩家。我有这个:
SELECT
COUNT(DISTINCT playerID)
FROM
table
WHERE
game_date > '$date'
HAVING
SUM(points) >= 300
这也包括总和少于 300 分的玩家。我该如何解决这个问题?
我想计算在给定日期之后总分至少为 300 的所有玩家。我有这个:
SELECT
COUNT(DISTINCT playerID)
FROM
table
WHERE
game_date > '$date'
HAVING
SUM(points) >= 300
这也包括总和少于 300 分的玩家。我该如何解决这个问题?
为此使用子查询:
SELECT COUNT(*) FROM
(
SELECT playerID, SUM(points) AS `total`
FROM `table`
WHERE game_date > '$date'
GROUP BY playerID
) tmp
WHERE total>=300
正如 Andre Bossard 所指出的:
要获得所有积分>=300 的玩家的列表:
SELECT * FROM (SELECT playerID, SUM(points) points FROM table WHERE game_date>'$date' GROUP BY playerID) a WHERE points>=300
要获得计数:
SELECT COUNT(*) FROM (SELECT playerID, SUM(points) points FROM table WHERE game_date>'$date' GROUP BY playerID) a WHERE points>=300