← Practice

Orders in progress: 'Москва', week of October 1, 2025

Level: SeniorTopic: Gaps and islands, sessions200 XP

Instructions

A delivery interval runs from created_at to delivered_at. Take the 'delivered' deliveries of restaurants in the city 'Москва' created from October 1, 2025 to October 7, 2025 inclusive and merge their overlapping intervals (touching also merges: one delivery created exactly at the moment another is handed over) into periods during which the city had at least one such order in progress. For each period, output busy_from and busy_to (its start and end), orders_cnt (the number of deliveries in it) and busy_minutes (the length of the period in minutes, rounded to 1 decimal place). Sort by busy_from.

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

deliveries.restaurant_id (0…N) ↔ restaurants.id (1…1)deliveries.customer_id (0…N) ↔ customers.id (1…1)deliveries.courier_id (0…N) ↔ couriers.id (0…1)couriersPKidintegercustomersPKidintegerdeliveriesPKidintegerFKrestaurant_idintegerFKcustomer_idintegerFKcourier_idintegerrestaurantsPKidinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-onedeliveries.restaurant_id → restaurants.id
  • N:1Many-to-onedeliveries.customer_id → customers.id
  • N:1Many-to-onedeliveries.courier_id → couriers.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema