Intermediate#05 · GROUP BY

Customers per country

Marketing wants to know where customers are. Return each country and its number of customers, largest first. Break ties alphabetically by country.

Write your query in the lab. It runs in your browser and tells you exactly what's wrong if it doesn't match.

Solve it in the lab

Hints

Hint 1

GROUP BY country makes one row per country.

Hint 2

Sort by the count descending, then by country: ORDER BY customers DESC, country.

Expected output

Your result should match this, in this order (7 rows).

countrycustomers
United States12
United Kingdom9
Portugal8
Canada7
Kenya6
Australia3
India3

Model answer

Show the solution
SELECT country, COUNT(*) AS customers
FROM customers
GROUP BY country
ORDER BY customers DESC, country;

Other queries that return the same rows are correct too. The lab checks your result, not your exact wording.

Next challenge: Shelf warmers →