SELECT house.villcode,
SUM(CASE WHEN person.typelive in ('1','3') 
AND GetAgeYearNum(person.birth,CURDATE()) < 60 
and personchronic.typedischart != '02' 
and visitepi.vaccinecode = 'FLU' THEN 1 ELSE '' END) as 'FLU'
FROM person INNER JOIN personchronic ON person.pid = personchronic.pid
INNER JOIN visitepi ON person.pcucodeperson = visitepi.pcucodeperson AND person.pid = visitepi.pid
INNER JOIN house ON person.pcucodeperson = house.pcucode
AND person.hcode = house.hcode
INNER JOIN village ON house.pcucode = village.pcucode
AND village.villcode = house.villcode
group by house.villcode;


