bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1194. Tournament Winners

1194. Tournament Winners

Leetcode Solutions

Aggregation and Ranking

  1. Use a UNION ALL to combine scores of players whether they are in the first_player or second_player position.
  2. Aggregate the total scores for each player using GROUP BY.
  3. Join the aggregated scores with the Players table to get the group_id for each player.
  4. Use the RANK() window function to assign a rank to each player within their group, ordered by total score descending and player_id ascending.
  5. Filter the results to only include players with a rank of 1, which are the winners in their groups.

erDiagram
    Players {
        int player_id
        int group_id
    }
    Matches {
        int match_id
        int first_player
        int second_player
        int first_score
        int second_score
    }
    Players ||--o{ Matches : "contains"

Aggregation with Conditional Sum and Minimum Player ID Selection

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR