Google-style Company ChallengeEasyVerified answerSQLite live

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_idINTEGER
  • countryVARCHAR(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, country

Why 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.

countryuser_count
USA6
Canada3
India3
UK3
Germany2
Australia1
Brazil1
France1
Italy1
Japan1

Previewing 10 of 12 expected rows. Run the query in the editor to inspect the full result.

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Interview Practice

Return to the complete interview preparation experience.