0

我想展示所有拥有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已经在字段列表中定义了为什么不起作用?

4

3 回答 3

3

having cnt > 4分组时必须使用

http://dev.mysql.com/doc/refman/5.0/en/group-by-hidden-columns.html

于 2010-09-27T22:01:10.510 回答
1

尝试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
于 2010-09-27T22:01:09.513 回答
0

尝试使用 HAVING 语句:

例如:

select title, AVG(salary)
from employee_data
GROUP BY title 
HAVING AVG(salary) > 100000;
于 2010-09-27T22:00:56.290 回答