Skip to main content
All Questions

Game Leaderboard

Hard
Unlock detailed company stats for this questionUpgrade

Zynga is a social game development company known for its popular games played by millions worldwide. Within their games, players can form teams and compete. Each player's performance in different game sessions is recorded as distinct score entries in the database.

You're provided two tables players and scores:

player_idplayer_nameteam_id
integerstringinteger
score_idplayer_idgame_score
integerintegerinteger

Write a SQL query to return the top 2 players from each team based on their single highest score across all sessions. Rank by distinct scores: return every player whose highest score is one of the two highest distinct scores on their team. Players with the same score share a place, so some teams will have more than two players in the result. For example, if two players tie at 110 and the next player has 100, all three are returned.