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

Top Two Orders per Customer

Return the two largest orders of every customer (id, customer_id, amount) ordered by customer_id then amount descending.

Table schema

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

Sample data

id | customer_id | amount
1 | 1 | 100
2 | 1 | 50
3 | 1 | 70
4 | 2 | 30

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.