gpt4 book ai didi

聚合函数上的 SQL 比较

转载 作者:行者123 更新时间:2023-12-04 20:32:22 34 4
gpt4 key购买 nike

当我在 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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com