runtime
81 / 139

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_idwins in 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
seasonteam_idwins
2016TEX95
2016WAS95
2017CLE102

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 seasonsas_of_datedate · unique idteam_idtext · links to teamswinsnumberlossesnumberruns_scorednumberruns_allowednumber
20162016-04-30ANA11138093
20162016-04-30ARI1214120138
20162016-04-30ATL51875122
20162016-04-30BAL14910886
20162016-04-30BOS1410126105
20162016-04-30CHA1789576
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 idfirst_game_datedatelast_regular_datedategames_per_teamnumberpostseason_teamsnumber
20162016-04-032016-10-0216210
20172017-04-022017-10-0116210
20182018-03-292018-09-3016210
20192019-03-202019-09-2916210
20202020-07-232020-09-276016
20212021-04-012021-10-0316210
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.

Debug: the second-best win total — SQL practice · Runtime