← Practice

Courier working-day streak: 'Москва', May–Jun 2025

Level: SeniorTopic: Gaps and islands, sessions200 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). For each courier from the city 'Москва' who had at least one working day in the period May 1, 2025 to June 30, 2025 inclusive, find the longest streak of consecutive working days within the period (no missing calendar days; if several streaks are equally long, the earliest one). Output courier_id, streak_days (the length of the streak in days), streak_start (its first day) and deliveries_cnt (the number of 'delivered' deliveries created on the days of the streak). Sort by streak_days descending, then courier_id 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