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.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.