I don't understand exactly what your query is surpossed to do, but here's my suggestion:select c.const_cd+' '+c.const_eng as Const_Name ,p.TotalPollingStn ,p.TotalS1 ,p.TotalS2 ,p.TotalS3 ,p.TotalS4 ,p.TotalS1+p.TotalS2+p.TotalS3+p.TotalS4 as TotalS1_S4 ,sign(p.TotalS1)+sign(p.TotalS2)+sign(p.TotalS3)+sign(p.TotalS4) as BoothEffect from constituency as c inner join (select const_cd ,count(polling_cd) as TotalPollingStn ,sum(case when s1=1 then 1 else 0 end) as TotalS1 ,sum(case when s1=2 then 1 else 0 end) as TotalS2 ,sum(case when s1=3 then 1 else 0 end) as TotalS3 ,sum(case when s1=4 then 1 else 0 end) as TotalS4 from pollingstation group by const_cd ) as p on p.const_cd=c.const_cd order by const_cd ,const_eng