my query is
select m.year_id,Count(*) as Distinctions from NewTestDB.dbo.[Master_MARKS2005] as m
join NewTestDB.dbo.Master_Student as s
on s.Student_id=m.Student_Id
join NewTestDB.dbo.Master_School as sc
on sc.school_id=s.school_code
where sc.SCHOOL_CODE= 'an0001' and m.YEAR_ID between 1 and 8 and m.[NRC_CLASS]='D'
group by m.year_id,
i want out of all year_id’s between 1 to 8 but now i am getting only when m.[NRC_CLASS]=’D’
how to rewrite this query so that i can get count as ‘0’ when no rows in the m.NRC_CLASS column contains ‘D’ value
You should use Left Join to achieve this
Like you can try this