我试图仅显示多个人在我的表中的邮政编码,并按升序对其进行排序。
我已经尝试了以下方法,但是它不起作用。
SELECT zipcode AS "zipcodes" FROM people GROUP BY zipcode ORDER BY ASC;
最佳答案
SELECT zipcode AS "zipcodes", count(1) as ZIP_COUNT
FROM people
GROUP BY zipcode
ORDER BY ZIP_COUNT ASC;
如果您只需要显示2次以上的邮政编码,请追加(在订购之前):
HAVING COUNT(1) > 1
或者(如果Mysql在HAVING子句中支持别名):
HAVING ZIP_COUNT > 1
关于mysql - 使用MYSQL仅选择匹配的邮政编码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50872625/