SQL Fundamentals · SQL problem
Revenue by Country
A free sql problem from the GROUP BY, HAVING and Conditional Aggregation skill. Read it here, then solve it in the app.
- Easy
- SQL problem
- Free
The problem
The expansion team wants to know which countries are worth a local-language site. Revenue counts
only orders that went through - status paid, shipped or delivered; pending, cancelled and
refunded orders don't count.
For every country with at least $100.00 of such revenue, return:
| column | meaning |
|---|---|
country | the customer's country |
orders | the number of counted orders |
revenue | the sum of their totals |
Sort by revenue from highest to lowest, then by country alphabetically. Guest checkouts have no
customer, and so no country - leave them out.
How it's graded
- Your SQL runs on PostgreSQL 18. Run compares your rows with the expected rows on the sample data; Submit runs it against hidden datasets built to catch the classic mistakes.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
More problems in GROUP BY, HAVING and Conditional Aggregation
Write the query Revenue by Country free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime