Top Countries by Users
Which countries have the most users, ranked from highest to lowest?
- Aggregation
- Sorting
Challenge brief
Understand the request
Market Intelligence needs a country-level user ranking to prioritise Google product localisation efforts.
Return country, user_count in the declared deterministic order.
Return
- country
- user_count
Constraints
- Return one row per country
- Order by user count descending, then country
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
users
user_idINTEGERcountryVARCHAR(50)device_typeVARCHAR(20)signup_dateDATE
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Count registered users at country grain.
Hint 2
The largest groups should appear first.
Hint 3
Add country name to resolve equal counts.
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 user_count DESC, countryWhy this works
Same aggregation as Q3 but with ORDER BY user_count DESC. USA has 5 users (users 1, 2, 6, 11, 19). UK, India, Canada each have 3. The remaining 8 countries each have exactly 1 user.
Success check
Returns the complete deterministic result for top countries by users
Expected result
Use this output to verify values, aliases, ordering, and row count.
| country | user_count |
|---|---|
| USA | 6 |
| Canada | 3 |
| India | 3 |
| UK | 3 |
| Germany | 2 |
| Australia | 1 |
| Brazil | 1 |
| France | 1 |
| Italy | 1 |
| Japan | 1 |
Previewing 10 of 12 expected rows. Review the published expected result before browsing the runnable collection.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Meta
Independent Meta-style social-product, engagement, content, community, messaging, and advertising SQL practice.
Microsoft
Independent Microsoft-style cloud, productivity, subscription, usage, support, and customer analytics SQL practice.
Netflix
Independent Netflix-style streaming, subscription, catalog, ratings, and engagement SQL practice.
Return to the complete interview preparation experience.