如何使Count函数返回0?

时间:2009-09-10 14:55:32

标签: sql function count

我正在尝试在Access中创建一系列查询,以计算77个县中每个县的每个种族的客户数量。

这是我的一个查询的SQL代码,我正在尝试为此...

SELECT [ClientsByCounty-Asian].County, [ClientsByCounty-Asian].CountyName, Count([ClientsByCounty-Asian].Asian) AS CountOfAsian
FROM [ClientsByCounty-Asian]
GROUP BY [ClientsByCounty-Asian].County, [ClientsByCounty-Asian].CountyName;

此查询仅返回77个县中的16个。我需要它显示所有77个县,即使结果为零并且没有记录。

如何让它显示其他61个县?

1 个答案:

答案 0 :(得分:8)

假设您的77个县存储在名为Counties的表格中<:p>

SELECT  c.CountyName, COUNT([ClientsByCounty-Asian].County)
FROM    Counties c
LEFT JOIN
        [ClientsByCounty-Asian]
ON      [ClientsByCounty-Asian].County = c.County
GROUP BY
        c.County, c.CountyName