Average days between orders
For every customer with at least two completed orders, find the average number of days between one completed order and their next one.
- use calendar dates of
order_ts, so two orders on the same day are 0 days apart - "next one" means next in time, not next by
order_id - round
avg_days_betweento 1 decimal place - guest orders (no
customer_id) don't belong to a customer, leave them out
Example: completed orders on Jan 1, Jan 3 and Jan 4 give gaps of 2 and 1, so the average is 1.5.
output columns
customer_idavg_days_betweenuses
ctrl + enter to run on the sample data · ctrl + shift + enter to submit
run your query to see the output here. Submit checks it against the sample data, hidden test cases, random data and a large dataset.