RienSQL
TASK #212 · Hard · Glovo

Peak Hour in Each City

Your brief
To plan courier shifts, Glovo looks for the hour with the most orders in each city. All orders in orders count, including cancelled ones, across all dates. An order's city is the city of its store, stores.city.

Write a query that for every city returns city, peak_hour (the hour of the day from created_at with the most orders, 0 to 23) and orders_count (that number of orders). If several hours tie for first place, return each of them as a separate row. Sort by city alphabetically, then by peak_hour ascending.
Expected columnscity peak_hour orders_countGlovo
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
storesstore_id, store_name, category, city, x, y
courierscourier_id, courier_name, city, vehicle
ordersorder_id, store_id, courier_id, status, created_at, promised_minutes, delivered_at, courier_start_x, courier_start_y, dropoff_x, dropoff_y, order_total