Shopify merchants want to know how often repeat customers come back. For each customer, consider their orders sorted by `order_date` (with `order_id` breaking ties on the same day) and compute the number of days between each order and the one before it. Return `customer_id`, `orders_count` (total orders) and `avg_days_between_orders` (average of those gaps, rounded to 2 decimals) for customers with at least 2 orders. Order the results by `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.