我有一张桌子,我正在尝试建立一个包含表格中两次以上出现次数的所有城市的明确列表。我正在尝试当前查询我被告知“函数计数不存在”?我做错了什么?
SELECT COUNT (city)
FROM `table1`
GROUP BY city
HAVING COUNT (city) >=2
答案 0 :(得分:10)
您的查询是正确的,您在COUNT
和(城市)之间留出了空格,它必须是COUNT(City)
。这将很好。您的查询应该是这样的:
SELECT City, COUNT(city) Counts
FROM `table1`
GROUP BY City
HAVING COUNT(city) >=2;
答案 1 :(得分:-1)
使用ALIAS
SELECT COUNT(city) as SOME_TEXT FROM table1 GROUP BY city HAVING SOME_TEXT >=2