Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Longest Gap Between Orders

For each customer return the longest gap in days between two consecutive orders (NULL if the customer has fewer than two orders). 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-01-01
2 | 1 | 2026-01-11
3 | 1 | 2026-02-20
4 | 2 | 2026-03-01

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.