你能试试这个
SELECT GameScores.player_id, GameScores.session_id
FROM (
SELECT player_id,MAX(score) as SecondScore
FROM GameScores g
WHERE score < (SELECT Max(Score) FROM gameScore where gameScore.player_id = g.player_id)
GROUP BY player_id
) x
INNER JOIN GameScores ON x.player_id = gamescore.player_id
AND x.SecondScore = gamescore.score
这是为每个玩家选择第二个高分的查询
SELECT player_id,MAX(score) as SecondScore
FROM GameScores g
WHERE score < (SELECT Max(Score) FROM gameScore where gameScore.player_id = g.player_id)
GROUP BY player_id
您不能在此查询中按会话分组。所以这就是为什么你需要把它放在一个子查询中并加入它gamescore
以获得session_id