Practice · medium · dataset: ecom
Customer order span
For each customer who has ordered, report their first and last order dates and the number of days between them.
Return customer_id, email, first_order_date, last_order_date, and days_span. Sort by
days_span descending, then by customer_id ascending.
Tables available
| Table | Columns |
|---|---|
customers |
customer_id, email, country, signup_date |
orders |
order_id, customer_id, order_date, status, channel |
A customer with a single order has a span of 0. Customers with no orders should not appear.
⌘/Ctrl + Enter to grade
Write a query, then grade it.
Hints
Try it first. Reveal a hint only when you are stuck.