TASK #212 · Hard · GlovoPeak 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.
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.
Ctrl / ⌘ + ↵
Result
Write a query and run it to see the results.
Schema
storesstore_id, store_name, category, city, x, ycourierscourier_id, courier_name, city, vehicleordersorder_id, store_id, courier_id, status, created_at, promised_minutes, delivered_at, courier_start_x, courier_start_y, dropoff_x, dropoff_y, order_total