Steadily Climbing Athletes
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.
| athlete_id | full_name |
|---|---|
| 1 | Mara Velasquez |
| 2 | Theo Nakamura |
| 3 | Priya Anand |
| result_id | athlete_id | race_day | fitness_score |
|---|---|---|---|
| 1 | 1 | 2024-02-03 | 40 |
| 2 | 1 | 2024-03-09 | 55 |
| 3 | 1 | 2024-04-12 | 60 |
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