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 and revenue for buyers with revenue at least 200.
Result columns · in this order
buyer_idrevenueHow to approach it
Aggregate in a FROM subquery, then filter revenue in the outer SELECT.
Sample input
| order_id | buyer_id | total_amount |
|---|---|---|
| 1001 | 1 | 80 |
| 1004 | 1 | 220 |
| 1009 | 1 | 30 |
| 1003 | 4 | 40 |
| 1008 | 4 | 150 |
5 rows — all rows shown.
Expected output
| buyer_id | revenue |
|---|---|
| 6 | 700 |
| 2 | 650 |
| 1 | 330 |
| 3 | 290 |
4 rows — all rows shown.
Constraints
Use a derived table in FROM. Order by revenue DESC, buyer_id ASC.
Expected skills
Derived tables, aggregation, and outer-query filtering.
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.