AnalystPath

Steadily Climbing Athletes

SQLMediumMid level~15 min

Problem

A training club records a fitness score for each athlete after every race. Find every athlete whose three most recent races (by race day) show a strictly increasing fitness score. Only consider athletes with at least three recorded races. Report the climb amount as the score of the latest of those three races minus the score of the earliest. Sort by climb amount from highest to lowest, then by athlete name alphabetically.

Tables

Example rows — the live problem includes the full dataset.

athletes
athlete_idfull_name
1Mara Velasquez
2Theo Nakamura
3Priya Anand
race_results
result_idathlete_idrace_dayfitness_score
112024-02-0340
212024-03-0955
312024-04-1260

Expected output

Your answer should return 2 rows with the columns athlete_id, full_name, gain.

Starter code (SQL)

SELECT *
FROM athletes;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions