我有一种情况,我需要根据某个列值 (如下所示)对申请人进行分组并找到该组的计数。当前,查询仅返回计数大于 0 的列。
应该对查询进行哪些修改,以便将所有组及其计数显示为零?
询问:
select Applicant_info.range as [Income Range], count(*) as [Total Students],order_number =
CASE range
WHEN 'Did not specify' THEN '1'
WHEN '0-25000' THEN '2'
WHEN '25001-50000' THEN '3'
WHEN '50001-75000' THEN '4'
WHEN '75001-100000' THEN '5'
WHEN '100001-200000' THEN '6'
WHEN '200000 and Above' THEN '7'
END
from (
select case
when Annual_Income is null or Annual_Income = '' then 'Did not specify'
when Annual_Income between 0 and 25000 then '0-25000'
when Annual_Income between 25001 and 50000 then '25001-50000'
when Annual_Income between 50001 and 75000 then '50001-75000'
when Annual_Income between 75001 and 100000 then '75001-100000'
when Annual_Income between 100001 and 200000 then '100001-200000'
when Annual_Income > 200000 then '200000 and Above'
end as range
from Applicant_info)Applicant_info
group by Applicant_info.range
order by order_number