当我在 ACCESS 2007 中运行以下 SQL 时
Select Location, COUNT(ApartmentBuildings) AS TotalIBuildingsManaged From Apartments Where COUNT(ApartmentBuildings) > 3 Group By Location Order By COUNT(ApartmentBuildings) DESC;
我收到以下错误:
where 子句中不能有聚合函数。我应该如何形成此查询以获取所有公寓楼数大于 3 的位置?
最佳答案
使用 having
而不是 where
:
Select Location, COUNT(ApartmentBuildings) AS TotalIBuildingsManaged
From Apartments
Group By Location
Having COUNT(ApartmentBuildings) > 3
Order By COUNT(ApartmentBuildings) DESC;
更多信息see this page
关于聚合函数上的 SQL 比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6204597/