我有一个像这样的查询
SELECT 'Education' as Purpose,ate_sex, Age_range, COUNT(*) AS Total
FROM (
SELECT dbo.ClientMain.ate_sex, dbo.ClientMain.ate_Id,
CASE
WHEN ate_Age BETWEEN 15 AND 19 THEN '15-19'
WHEN ate_Age BETWEEN 20 AND 24 THEN '20-24'
WHEN ate_Age BETWEEN 25 AND 34 THEN '25-34'
WHEN ate_Age BETWEEN 35 AND 44 THEN '35-44'
WHEN ate_Age BETWEEN 45 AND 54 THEN '45-54'
WHEN ate_Age BETWEEN 55 AND 64 THEN '55-64'
ELSE '80+' END AS Age_range
FROM dbo.ClientMain
INNER JOIN dbo.ClientSub ON dbo.ClientMain.ate_Id = dbo.ClientSub.ate_Id
WHERE (dbo.ClientSub.chk_Name = N'Assistance')
) AS t group by ate_sex,Age_range
它将数据返回为:
但我想要我的结果,因为当他的年龄范围在 15-19 之间没有记录时,它必须返回零。作为教育男性 15-19 0 这些是我的表格 任何人都可以修改我的查询以获取零以表示没有记录。