Тази заявка трябва да получи това, от което се нуждаете:
SELECT
player_id, game_id, score
FROM
(
SELECT game_id,MAX(score) AS MaxScore
FROM games
GROUP BY game_id
) AS Winners
JOIN games
ON (games.game_id = Winners.game_id AND games.score = Winners.MaxScore)
Предполага се, че равенството е победа и за двамата играчи.
Ако искате да получите само играча и неговия брой победи, можете да използвате тази заявка:
SELECT
player_id, COUNT(*) AS wins
FROM
(
SELECT game_id,MAX(score) AS MaxScore
FROM games
GROUP BY game_id
) AS Winners
JOIN games
ON (games.game_id = Winners.game_id AND games.score = Winners.MaxScore)
WHERE player_id = {player_id}
GROUP BY player_id
Просто заменете {player_id}
с играча, който търсите и wins
е техният брой победи или равенства.