Second Order Window

Start Timer

0:00:00

Upvote
8
Downvote
Save question
View comments

We’re given an orders table where each row represents a single order placed by a customer.

Write a query that finds, for each customer who has placed at least two orders, the number of calendar days between the dates of their first and second order (ignore the time of day), and return only the customers where this number is 30 or less.

Note: If a customer places two orders at the same time, the lower id is treated as the earlier order.

Example:

Input:

orders table

Column Type
id INTEGER
customer_id INTEGER
order_date DATETIME
amount FLOAT

Output:

Column Type
customer_id INTEGER
days_between INTEGER
.
.
.
.
.


Comments

Loading comments