← Retention, funnels, cohorts

Repeat in 60 days: Feb–May 2025, paid+shipped

Level: Senior200 XP

Instructions

Consider only paid and shipped orders (status 'paid' or 'shipped'). A customer's first order is their earliest such order over the whole history (by created_at); the cohort is the month of the first order (cohort_month is the first day of the month). Take customers whose first order was placed from February 1, 2025 to May 31, 2025 inclusive. A customer placed a repeat order within 60 days if they have another counted order strictly later than the first one and no later than 60 days after it (created_at <= first + interval '60 days'). For each cohort, output cohort_month, customers (the number of customers in the cohort), repeaters (the number of customers with a repeat order) and repeat_rate_pct (repeaters / customers × 100, rounded to 1 decimal place). Sort by cohort_month.

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

order_items.order_id (0…N) ↔ orders.id (1…1)order_items.product_id (0…N) ↔ products.id (1…1)orders.customer_id (0…N) ↔ customers.id (1…1)products.category_id (0…N) ↔ categories.id (1…1)categoriesPKidintegercustomersPKidintegerimport_logPKidintegerorder_itemsPKFKorder_idintegerPKFKproduct_idintegerordersPKidintegerFKcustomer_idintegerproductsPKidintegerFKcategory_idinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneorder_items.order_id → orders.id
  • N:1Many-to-oneorder_items.product_id → products.id
  • N:1Many-to-oneorders.customer_id → customers.id
  • N:1Many-to-oneproducts.category_id → categories.id

Table data

PostgreSQL

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

Dataset schema