← Practice

Courier idle periods of 7+ days: 'Екатеринбург', bike

Level: MiddleTopic: Gaps and islands, sessions100 XP

Instructions

A courier's working day is a calendar day on which at least one of the courier's deliveries with status 'delivered' was created (by created_at). An idle period is an unbroken run of days without working days between two consecutive working days of a courier (days before the first and after the last working day do not count). For couriers from the city 'Екатеринбург' with vehicle 'bike', find all idle periods of at least 7 days over the whole time. Output courier_id, idle_from and idle_to (the first and last day of the idle period) and idle_days (the number of days in it; between working days March 1 and March 4 the idle period lasts 2 days). Sort by idle_days descending, then courier_id, then idle_from ascending.

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