Amazon Prime retention teams study purchase pacing to optimize re-engagement notifications. Write a SQL query using the `LAG()` window function to calculate the average number of days between consecutive orders for each customer. Return `customer_id` and `avg_days_between_orders` (rounded to 2 decimal places). Exclude customers who have only placed a single order, as no interval exists for them. Sort results by `avg_days_between_orders` ascending, then `customer_id` ascending.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.