Reputation: 3797
I have a table where I am trying to build a distinct list of all the cities with more than two occurrences in the table. I am trying the current query am am told "function count does not exist"? What am I doing wrong?
SELECT COUNT (city)
FROM `table1`
GROUP BY city
HAVING COUNT (city) >=2
Upvotes: 4
Views: 22778
Reputation: 1509
Your query is correct you have given a space between COUNT
and (City) it must be COUNT(City)
. that will work fine. Your query should be like this:
SELECT City, COUNT(city) Counts
FROM `table1`
GROUP BY City
HAVING COUNT(city) >=2;
Upvotes: 12
Reputation: 1404
USE ALIAS
SELECT COUNT(city) as SOME_TEXT FROM table1 GROUP BY city HAVING SOME_TEXT >=2
Upvotes: -1