task RANK / DENSE_RANK · medium
Debug: the second-best win total
Return team_id and wins for every team tied at the second-highest distinct win total in each season’s final standings. The query keeps only one row per position. Fix it.
what to return
- Columns
seasonteam_idwinsin this order- Rows
- 11 rows · any order
- Skill
- Repair the query’s logic and confirm the fix on changed data. Refresher: RANK & DENSE_RANK →
expected result
Your query should return exactly these columns and values. Run it and compare.
expected result11 rows · any order
| season | team_id | wins |
|---|---|---|
| 2016 | TEX | 95 |
| 2016 | WAS | 95 |
| 2017 | CLE | 102 |
first 3 of 11 rows
data you can query
Sports dataset: the first 6 rows of each table. Under each column name: the kind of value it holds, and which table it links to. Your queries run on all rows.
standings7 columns · 2,010 rows
| seasonnumber · links to seasons | as_of_datedate · unique id | team_idtext · links to teams | winsnumber | lossesnumber | runs_scorednumber | runs_allowednumber |
|---|---|---|---|---|---|---|
| 2016 | 2016-04-30 | ANA | 11 | 13 | 80 | 93 |
| 2016 | 2016-04-30 | ARI | 12 | 14 | 120 | 138 |
| 2016 | 2016-04-30 | ATL | 5 | 18 | 75 | 122 |
| 2016 | 2016-04-30 | BAL | 14 | 9 | 108 | 86 |
| 2016 | 2016-04-30 | BOS | 14 | 10 | 126 | 105 |
| 2016 | 2016-04-30 | CHA | 17 | 8 | 95 | 76 |
- seasonnumber · links to seasons
- 2016
- as_of_datedate · unique id
- 2016-04-30
- team_idtext · links to teams
- ANA
- winsnumber
- 11
- lossesnumber
- 13
- runs_scorednumber
- 80
- runs_allowednumber
- 93
- seasonnumber · links to seasons
- 2016
- as_of_datedate · unique id
- 2016-04-30
- team_idtext · links to teams
- ARI
- winsnumber
- 12
- lossesnumber
- 14
- runs_scorednumber
- 120
- runs_allowednumber
- 138
- seasonnumber · links to seasons
- 2016
- as_of_datedate · unique id
- 2016-04-30
- team_idtext · links to teams
- ATL
- winsnumber
- 5
- lossesnumber
- 18
- runs_scorednumber
- 75
- runs_allowednumber
- 122
- seasonnumber · links to seasons
- 2016
- as_of_datedate · unique id
- 2016-04-30
- team_idtext · links to teams
- BAL
- winsnumber
- 14
- lossesnumber
- 9
- runs_scorednumber
- 108
- runs_allowednumber
- 86
- seasonnumber · links to seasons
- 2016
- as_of_datedate · unique id
- 2016-04-30
- team_idtext · links to teams
- BOS
- winsnumber
- 14
- lossesnumber
- 10
- runs_scorednumber
- 126
- runs_allowednumber
- 105
- seasonnumber · links to seasons
- 2016
- as_of_datedate · unique id
- 2016-04-30
- team_idtext · links to teams
- CHA
- winsnumber
- 17
- lossesnumber
- 8
- runs_scorednumber
- 95
- runs_allowednumber
- 76
first 6 of 2,010 rows · your queries use all of them
seasons5 columns · 10 rows
| seasonnumber · unique id | first_game_datedate | last_regular_datedate | games_per_teamnumber | postseason_teamsnumber |
|---|---|---|---|---|
| 2016 | 2016-04-03 | 2016-10-02 | 162 | 10 |
| 2017 | 2017-04-02 | 2017-10-01 | 162 | 10 |
| 2018 | 2018-03-29 | 2018-09-30 | 162 | 10 |
| 2019 | 2019-03-20 | 2019-09-29 | 162 | 10 |
| 2020 | 2020-07-23 | 2020-09-27 | 60 | 16 |
| 2021 | 2021-04-01 | 2021-10-03 | 162 | 10 |
- seasonnumber · unique id
- 2016
- first_game_datedate
- 2016-04-03
- last_regular_datedate
- 2016-10-02
- games_per_teamnumber
- 162
- postseason_teamsnumber
- 10
- seasonnumber · unique id
- 2017
- first_game_datedate
- 2017-04-02
- last_regular_datedate
- 2017-10-01
- games_per_teamnumber
- 162
- postseason_teamsnumber
- 10
- seasonnumber · unique id
- 2018
- first_game_datedate
- 2018-03-29
- last_regular_datedate
- 2018-09-30
- games_per_teamnumber
- 162
- postseason_teamsnumber
- 10
- seasonnumber · unique id
- 2019
- first_game_datedate
- 2019-03-20
- last_regular_datedate
- 2019-09-29
- games_per_teamnumber
- 162
- postseason_teamsnumber
- 10
- seasonnumber · unique id
- 2020
- first_game_datedate
- 2020-07-23
- last_regular_datedate
- 2020-09-27
- games_per_teamnumber
- 60
- postseason_teamsnumber
- 16
- seasonnumber · unique id
- 2021
- first_game_datedate
- 2021-04-01
- last_regular_datedate
- 2021-10-03
- games_per_teamnumber
- 162
- postseason_teamsnumber
- 10
first 6 of 10 rows · your queries use all of them
solution.sql
Hints and the answer are always available. Using them counts the question as solved with help.