Top Two Orders per Customer
Medium
Ranking & Top-N
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.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.