Breakthrough Third Session
Problem
Table: `workout`
| Column Name | Type |
|---|---|
| athlete_id | int |
| distance_km | decimal(5,2) |
| logged_at | datetime |
There is no single-column primary key; `(athlete_id, logged_at)` is unique. Each row is a logged workout for an athlete.
For every athlete, look at their third workout in chronological order. Return that workout only if its `distance_km` is strictly greater than both the athlete's first and second workouts. Output `athlete_id`, the third workout's distance as `breakthrough_distance`, and its timestamp as `breakthrough_at`, ordered by `athlete_id`.
Tables
Example rows — the live problem includes the full dataset.
| athlete_id | distance_km | logged_at |
|---|---|---|
| 1 | 3 | 2024-01-01 06:00:00 |
| 1 | 4.5 | 2024-01-03 06:00:00 |
| 1 | 6.2 | 2024-01-05 06:00:00 |
Expected output
Your answer should return 1 row with the columns athlete_id, breakthrough_distance, breakthrough_at.
Starter code (SQL)
SELECT *
FROM workout;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