SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Amazon: Days Between Repeat Orders

Unsolved

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.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
🏢 Amazon

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM orders
Full source dataset
12 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine