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

Sum of the Last Three Orders

Medium Window Frames

For each order return the sum of that order and the two orders before it for the same customer (fewer when not available), ordered by id.

Table schema

Orders(id INT PRIMARY KEY, customer_id INT, amount INT)

Sample data

id | customer_id | amount
1 | 1 | 10
2 | 1 | 20
3 | 1 | 30
4 | 1 | 40

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.