获取COUNT()结果SQL的SUM()

时间:2017-10-10 06:21:37

标签: sql-server

我有一个查询找到有2个或更多地址的BusinessEntityID - 这样可以正常工作,结果我得到36行,表明有36个商家有两个或更多地址。

SELECT count(BusinessEntityID) FROM Person.BusinessEntityAddress
GROUP BY BusinessEntityID
HAVING COUNT(BusinessEntityID) >= 2

如何修改此查询以便对结果求和?我需要我的最终结果是计算我得到多少结果(36)而不是行本身。

谢谢

1 个答案:

答案 0 :(得分:1)

如果您只想要最终计数,那么:

SELECT COUNT(count) from
(SELECT count(BusinessEntityID) AS count FROM Person.BusinessEntityAddress
GROUP BY BusinessEntityID
HAVING COUNT(BusinessEntityID) >= 2) AS t