sql server - How to select all the records even if there is no data in sql -
i have query like
select 'education' purpose,ate_sex, age_range, count(*) total ( select dbo.clientmain.ate_sex, dbo.clientmain.ate_id, case when ate_age between 15 , 19 '15-19' when ate_age between 20 , 24 '20-24' when ate_age between 25 , 34 '25-34' when ate_age between 35 , 44 '35-44' when ate_age between 45 , 54 '45-54' when ate_age between 55 , 64 '55-64' else '80+' end age_range dbo.clientmain inner join dbo.clientsub on dbo.clientmain.ate_id = dbo.clientsub.ate_id (dbo.clientsub.chk_name = n'assistance') ) t group ate_sex,age_range
which returns data as:
but want result when there no record age range in 15-19, have return zero. education male 15-19 0 these tables can please modify query zeros no records.
use
left join
instead ofinner join
use
isnull(count(*), 0)
instead ofcount(*)
. alternatively, can usetotal = case when count(*) null 0 else count(*) end
Comments
Post a Comment