Reputation: 193
I have a MySQL column named "country" in table named "contact".
I need to write a query to return all the distinct countries in that column, and how many times they occur.
I am trying with:
SELECT SUM([DISTINCT] country) FROM contact GROUP BY country
Where am I going wrong? Thanks!
Upvotes: 0
Views: 39
Reputation: 106
Following should work
SELECT COUNT(country) AS Num_of_country, country
FROM Contact
GROUP BY country
Upvotes: 1
Reputation: 61512
This will return the name of the Country and the number of times that Country appeared in the column:
SELECT country, COUNT(*) as count
FROM Contact
GROUP BY country
ORDER BY count DESC
it also returns the countries in order of most to least frequent.
Upvotes: 3