You are given information about tennis players and their Grand Slam tournament wins. The Players table contains player information, and the Championships table contains the winners of each Grand Slam tournament by year.
Table: Players
player_id(int): Primary key, unique identifier for each playerplayer_name(varchar): Name of the tennis player
Table: Championships
year(int): Primary key, tournament yearWimbledon(int): Player ID who won WimbledonFr_open(int): Player ID who won French OpenUS_open(int): Player ID who won US OpenAu_open(int): Player ID who won Australian Open
Write a SQL query to report the number of Grand Slam tournaments won by each player. Do not include players who did not win any tournament. Return the result in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
player_id
PK
|
int | Primary key, unique identifier for each player |
player_name
|
varchar | Name of the tennis player |
| Column Name | Type | Description |
|---|---|---|
year
PK
|
int | Primary key, tournament year |
Wimbledon
|
int | Player ID who won Wimbledon that year |
Fr_open
|
int | Player ID who won French Open that year |
US_open
|
int | Player ID who won US Open that year |
Au_open
|
int | Player ID who won Australian Open that year |
Input & Output
| player_id | player_name |
|---|---|
| 1 | Novak Djokovic |
| 2 | Rafael Nadal |
| 3 | Roger Federer |
| year | Wimbledon | Fr_open | US_open | Au_open |
|---|---|---|---|---|
| 2018 | 1 | 2 | 1 | 3 |
| 2019 | 1 | 2 | 2 | 1 |
| player_name | grand_slams_count |
|---|---|
| Novak Djokovic | 3 |
| Rafael Nadal | 3 |
| Roger Federer | 1 |
Novak Djokovic (ID=1) won Wimbledon 2018, US Open 2018, and Australian Open 2019 = 3 titles. Rafael Nadal (ID=2) won French Open 2018, French Open 2019, and US Open 2019 = 3 titles. Roger Federer (ID=3) won Australian Open 2018 = 1 title.
| player_id | player_name |
|---|---|
| 1 | Serena Williams |
| 2 | Simona Halep |
| year | Wimbledon | Fr_open | US_open | Au_open |
|---|---|---|---|---|
| 2020 | 2 | 2 | 2 | 2 |
| player_name | grand_slams_count |
|---|---|
| Simona Halep | 4 |
Simona Halep (ID=2) won all four Grand Slam tournaments in 2020, giving her 4 titles. Serena Williams (ID=1) did not win any tournaments, so she is excluded from the result.
Constraints
-
1 ≤ player_id ≤ 1000 -
1980 ≤ year ≤ 2030 -
player_nameconsists of English letters and spaces only -
Each tournament winner
player_idexists in the Players table