Total Parking Minutes per Vehicle
Problem
Table: `parking_event`
| Column Name | Type |
|---|---|
| vehicle_id | int |
| park_date | date |
| enter_min | int |
| exit_min | int |
`(vehicle_id, park_date, enter_min)` is the primary key. Each row records one parking stay: a vehicle entered a garage at minute `enter_min` and left at minute `exit_min` on `park_date`. A vehicle may park several times in one day.
For each `park_date` and `vehicle_id`, report the total number of minutes the vehicle spent parked that day. Output columns `park_date` aliased `day`, `vehicle_id`, and the total aliased `total_minutes`.
Tables
Example rows — the live problem includes the full dataset.
| vehicle_id | park_date | enter_min | exit_min |
|---|---|---|---|
| 1 | 2026-02-10 | 30 | 90 |
| 1 | 2026-02-10 | 100 | 130 |
| 2 | 2026-02-10 | 0 | 45 |
Expected output
Your answer should return 3 rows with the columns day, vehicle_id, total_minutes.
Starter code (SQL)
SELECT *
FROM parking_event;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