Cumulative km: Санкт-Петербург, June 2025, from 2 km
Instructions
Select deliveries (completed, with a non-NULL delivered_at) whose delivered_at is on or after June 1, 2025 and strictly before July 1, 2025, whose distance_km is at least 2, made by couriers from the city 'Санкт-Петербург' (couriers.city). For each selected delivery compute running_total, the cumulative the sum of distance_km (the distance in km) over the selected deliveries of the same courier up to it (with the same distance_km filter): from their first such delivery through the current one inclusive, in chronological order (by delivered_at, ties by id). Output the delivery id, courier_id, delivered_at, distance_km and running_total. Sort by courier_id, then delivered_at, then id (all ascending).
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Table relationships
- N:1Many-to-one
deliveries.→restaurant_id restaurants.id - N:1Many-to-one
deliveries.→customer_id customers.id - N:1Many-to-one
deliveries.→courier_id couriers.id
Table data
Select a table in the diagram or list to view its rows.