我想展示所有拥有count > 5
. 我试图将我的结果限制在 5 以上,但它不起作用。
SELECT
user.city,
Count(user.city) AS cnt
FROM user
Inner Join zip ON zip.zip = user.zip
WHERE cnt > 5
GROUP BY user.city
WHERE cnt > 5 **<--------------- It fails here**
cnt
已经在字段列表中定义了为什么不起作用?
我想展示所有拥有count > 5
. 我试图将我的结果限制在 5 以上,但它不起作用。
SELECT
user.city,
Count(user.city) AS cnt
FROM user
Inner Join zip ON zip.zip = user.zip
WHERE cnt > 5
GROUP BY user.city
WHERE cnt > 5 **<--------------- It fails here**
cnt
已经在字段列表中定义了为什么不起作用?
having cnt > 4
分组时必须使用
http://dev.mysql.com/doc/refman/5.0/en/group-by-hidden-columns.html
尝试HAVING
SELECT user.city,
COUNT(user.city) AS cnt
FROM user
INNER JOIN zip ON zip.zip = user.zip
GROUP BY user.city
HAVING COUNT(user.city) > 5
尝试使用 HAVING 语句:
例如:
select title, AVG(salary)
from employee_data
GROUP BY title
HAVING AVG(salary) > 100000;