Practice · hard · dataset: ecom
Second order per customer
A retention analyst wants to see how quickly customers come back after their first purchase. For each customer with at least two orders, return their second order and how many days passed since their first.
Return customer_id, order_id, order_date, and days_since_previous_order. Order is defined
by order_date ascending, then order_id ascending to break same-day ties. Sort by customer_id
ascending.
Tables available
| Table | Columns |
|---|---|
orders |
order_id, customer_id, order_date, status, channel |
Customers with only one order do not appear. A second order placed on the same day as the first has
a gap of 0, not a missing row.
⌘/Ctrl + Enter to grade
Write a query, then grade it.
Hints
Try it first. Reveal a hint only when you are stuck.