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 status and buyers (the count of distinct buyer_id values) for each status. Order by buyers descending, then status ascending.
Result columns · in this order
statusbuyersHow to approach it
GROUP BY status with COUNT(DISTINCT buyer_id) AS buyers, then ORDER BY buyers DESC, status ASC.
Sample input
| order_id | buyer_id | status |
|---|---|---|
| 1001 | 1 | paid |
| 1002 | 3 | paid |
| 1005 | 2 | paid |
| 1007 | 3 | paid |
| 1010 | 6 | paid |
| 1011 | 2 | paid |
6 rows — all rows shown.
Expected output
| status | buyers |
|---|---|
| paid | 4 |
| shipped | 3 |
| pending | 2 |
| refunded | 1 |
4 rows — all rows shown.
Constraints
GROUP BY status. Use COUNT(DISTINCT buyer_id) AS buyers so repeat buyers are counted once. Order by buyers DESC, status ASC.
Expected skills
Counting unique entities with COUNT(DISTINCT ...) inside groups.
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.