Leetcode Problem 1783. Grand Slam Titles

1783. Grand Slam Titles

Leetcode Solutions

Aggregation and Conditional Sum

  1. Perform an inner join between the Players and Championships tables on the condition that player_id matches any of the winner columns in Championships.
  2. Use the SUM function with a conditional statement to count the number of grand slam titles for each player. This is done by adding 1 for each match of player_id with the winner columns and 0 otherwise.
  3. Group the results by player_id and player_name to get the total count of grand slam titles for each player.
  4. Filter out players who have not won any titles by ensuring the count is greater than zero.
  5. Select the player_id, player_name, and the sum as grand_slams_count to form the final output.

erDiagram
    Players {
        int player_id PK
        varchar player_name
    }

    Championships {
        int year PK
        int Wimbledon
        int Fr_open
        int US_open
        int Au_open
    }

Union All and Group By

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...