RienSQL
TASK #211 · Hard · Glovo

Courier Distance in March

Your brief
A Glovo courier's route for an order has two legs: from where the courier was when assigned the order (courier_start_x, courier_start_y) to the store (stores.x, stores.y), and from the store to the customer (dropoff_x, dropoff_y). A leg's length in kilometres is the city-block distance |x1 − x2| + |y1 − y2|.

Write a query that, over delivered orders (status = 'delivered') created in March 2025, returns for every courier courier_name, deliveries (the number of such orders) and total_km (the total route length, rounded to two decimals). Do not show couriers without such orders. Sort by total_km descending and, on ties, by courier_name alphabetically.
Expected columnscourier_name deliveries total_kmGlovo
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