帮助选择计数查询
我想显示 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
已经在字段列表中定义了,为什么不起作用?
I want to show all cities that have have a count > 5
. I have tried to limit my results anything over a count of 5 but it isn't working.
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
has already been defined in the field list so why doesn't work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须使用
having cnt > 4
当您分组http: //dev.mysql.com/doc/refman/5.0/en/group-by-hidden-columns.html
you must use
having cnt > 4
when you are groupinghttp://dev.mysql.com/doc/refman/5.0/en/group-by-hidden-columns.html
尝试
拥有
Try
HAVING
尝试使用 HAVING 语句:
例如:
Try using the HAVING statement:
For example: