AnalystPath

Average Workout Duration per Treadmill

SQLEasyJunior level~15 min

Problem

Table: `treadmill_log`

| Column Name | Type |
|---|---|
| treadmill_id | int |
| session_id | int |
| phase | text |
| moment | float |

`(treadmill_id, session_id, phase)` is the primary key. Each treadmill in a gym records two rows per workout session: one row with `phase = 'start'` and one with `phase = 'finish'`, where `moment` is the timestamp in seconds.

For every treadmill, compute the **average workout duration** across all of its sessions. The duration of a session is its finish timestamp minus its start timestamp. Round the answer to 3 decimal places and alias it `avg_duration`. Return one row per treadmill.

Tables

Example rows — the live problem includes the full dataset.

treadmill_log
treadmill_idsession_idphasemoment
110start100
110finish130
111start200

Expected output

Your answer should return 2 rows with the columns treadmill_id, avg_duration.

Starter code (SQL)

SELECT *
FROM treadmill_log;

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