Days Since Last Order
Medium
Time Series SQL
Treat 2026-10-06 as today. For each customer return the number of days since their most recent order. Order by customer_id.
Table schema
Orders(id INT PRIMARY KEY, customer_id INT, order_date DATE)Sample data
id | customer_id | order_date
1 | 1 | 2026-09-26
2 | 1 | 2026-10-01
3 | 2 | 2026-08-07
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.