AnalystPath

Busiest Scan Hour per Warehouse Zone

SQLMediumMid level~15 min

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.

scan_event
scanner_idparcel_idscanned_atzone
11002024-04-01 09:05:00Inbound
11012024-04-01 09:40:00Inbound
21022024-04-01 14:10:00Inbound

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

Related SQL questions