I have a situation in which i need to group the applicant based on some column value
(shown below) and find the count of that group.
Currently the query is returning only those columns which has a count of more than 0.
What modification should be done to the query so that it shows all groups and its counts as zero?
Query:
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
Use a separate
CASEexpression for each one like this:Note that: This
SUMfunction is actually a count, because it sums either 0 or 1.