← Practice

Churn, Aug 1, 2025: 45 days without orders, delivered

Level: MiddleTopic: Retention, funnels, cohorts100 XP

Instructions

Consider only delivered orders (status = 'delivered'), by the date created_at. The reporting date is August 1, 2025; orders from this date onward are not counted. An active customer is a customer with at least one such order strictly before August 1, 2025. An active customer is considered churned if they have no such orders from June 17, 2025 to July 31, 2025 inclusive (the 45 days before the reporting date). For each customer city (customers.city), output city, active_customers (the number of active customers), churned (the number of churned customers) and churn_pct (churned / active_customers × 100, rounded to 1 decimal place). Sort by city.

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