我正在检查一些住房数据,并希望列表中的邮政编码以及返回的计数值(对于看起来最少的邮政编码都是相同的)。但是,当我运行以下查询时,我只得到答案而不是相关的邮政编码(从检查,我知道有多个邮政编码具有相同的最小值)。我确实认识到这是由GROUP BY
函数引起的,它实际上是"分组"代码按最小值,但我不确定如何获得具有相关最小值的所有zipcode的列表。
SELECT MIN(counted)
FROM (SELECT zipcode, count(*) AS counted
FROM housingprices
GROUP BY zipcode)
AS COUNTS
答案 0 :(得分:3)
我认为你似乎想要:
SELECT zipcode, count(*) AS counted
FROM housingprices
GROUP BY zipcode
HAVING count(*) = (SELECT MIN(counted)
FROM (SELECT count(*) AS counted
FROM housingprices
GROUP BY zipcode)
);