Busiest Scan Hour per Warehouse Zone
Problem
Table: `scan_event`
| Column Name | Type |
|---|---|
| scanner_id | int |
| parcel_id | int |
| scanned_at | datetime |
| zone | varchar(40) |
There is no primary key; the table may contain duplicate rows. Each row is one parcel scan in a warehouse `zone` at the timestamp `scanned_at`.
For each `zone`, find the hour of day (0-23) during which the most scans occurred. If several hours tie for the maximum in a zone, return all of them. Return `zone`, the `busy_hour` as an integer, and the `scan_count`. Order the result by `busy_hour` descending, then `zone` descending.
Tables
Example rows — the live problem includes the full dataset.
| scanner_id | parcel_id | scanned_at | zone |
|---|---|---|---|
| 1 | 100 | 2024-04-01 09:05:00 | Inbound |
| 1 | 101 | 2024-04-01 09:40:00 | Inbound |
| 2 | 102 | 2024-04-01 14:10:00 | Inbound |
Expected output
Your answer should return 2 rows with the columns zone, busy_hour, scan_count.
Starter code (SQL)
SELECT *
FROM scan_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