Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Return buyer_id, revenue, and revenue_rank for the top 3 ranked buyers.
Result columns · in this order
buyer_idrevenuerevenue_rankHow to approach it
Aggregate first, rank second.
Sample input
| order_id | buyer_id | total_amount |
|---|---|---|
| 1010 | 6 | 640 |
| 1006 | 6 | 60 |
| 1005 | 2 | 540 |
| 1011 | 2 | 110 |
| 1001 | 1 | 80 |
5 rows — all rows shown.
Expected output
| buyer_id | revenue | revenue_rank |
|---|---|---|
| 6 | 700 | 1 |
| 2 | 650 | 2 |
| 1 | 330 | 3 |
3 rows — all rows shown.
Constraints
Aggregate revenue by buyer, rank by revenue descending, and keep rank <= 3.
Expected skills
Ranking grouped results with window functions.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.