所以我在表中有一个列有4个区域(NA,EMEA,LATAM,APAC)。我试图创建一个计算每个区域出现次数的查询。现在,我的查询是
USE CompDataCenters
GO
SELECT COUNT(Region) AS NA
FROM [CompDataCenters All In]
WHERE Region = 'NA'
但这只能告诉我总次数' NA'出现。如何编写显示所有区域计数的查询?或者我是否必须单独编写它们?
答案 0 :(得分:1)
只需使用GROUP BY
:
SELECT Region, COUNT(Region)
FROM [CompDataCenters All In]
GROUP BY Region;
答案 1 :(得分:0)
非常简单。
SELECT COUNT(Region) AS NA
FROM [CompDataCenters All In]
WHERE Region = 'NA'
Group by Region