Users by Country
For regional product planning, how many registered users are represented in each country?
- Aggregation
- Sorting
Challenge brief
Understand the request
International Sales needs to understand the geographic distribution of the user base to prioritise regional sales investments.
Count users per country from the users table.
Return
- country
- user_count
Constraints
- Return every represented country
- Order countries alphabetically
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
users
user_idINTEGERcountryTEXTsignup_dateDATE
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
All data is in users. GROUP BY country and COUNT rows per group. No JOIN needed.
Hint 2
SELECT country, COUNT(*) AS user_count FROM users GROUP BY country.
Hint 3
Build question 2 from the required result grain: choose the driving table, add only the joins and filters needed for that grain, then apply aggregation and deterministic ordering.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT country, COUNT(*) AS user_count FROM users GROUP BY country ORDER BY country;Why this works
GROUP BY country creates one group per country. COUNT(*) counts users in each group. US has 5 users (users 1, 3, 6, 8, 11). The 6 countries represent 12 total users.
Success check
6 countries — US leads with 5; CA and IN each have 2; DE, FR, UK each have 1
Expected result
Use this output to verify values, aliases, ordering, and row count.
| country | user_count |
|---|---|
| CA | 2 |
| DE | 1 |
| FR | 1 |
| IN | 2 |
| UK | 1 |
| US | 6 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Apple
Independent Apple-style product, retail, services, support, workforce, and device-usage SQL practice.
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Amazon
Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice.
Return to the complete interview preparation experience.