Game Leaderboard
HardUnlock 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:
Write a SQL query to return the top 2 players from each team based on their single highest score across all sessions. If multiple players share the same highest score, include all of them, which may result in more than two top players for some teams.
PlayerMaxScoresCTE (Common Table Expression) identifies the highest score achieved by each player across all their game sessions.RankedPlayersCTE then joins theplayerstable with thePlayerMaxScoresCTE to associate the highest scores with their respective players and teams. This CTE also assigns a ranking within each team based on the highest score usingDENSE_RANK().- The main query filters out the players ranked in the top 2 positions (or top positions if there are ties) from each team.