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:

enter image description here

but want result when there no record age range in 15-19, have return zero. education male 15-19 0 these tables enter image description here can please modify query zeros no records.

  • use left join instead of inner join

  • use isnull(count(*), 0) instead of count(*). alternatively, can use

    total = case when count(*) null 0 else count(*) end


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -