SELECT 
house.villcode,
SUM(CASE WHEN visitepi.vaccinecode LIKE 'DHB%' THEN 1 ELSE 0 END) AS DHB_All,
SUM(CASE WHEN visitepi.vaccinecode LIKE 'DTP%' THEN 1 ELSE 0 END) AS DTP_All, 
SUM(CASE WHEN visitepi.vaccinecode LIKE 'OPV%' THEN 1 ELSE 0 END) AS OPV_All,
SUM(CASE WHEN visitepi.vaccinecode = 'MMR' THEN 1 ELSE 0 END) AS MMR, 
SUM(CASE WHEN visitepi.vaccinecode LIKE 'JE%' THEN 1 ELSE 0 END) AS JE_All,
SUM(CASE WHEN visitepi.vaccinecode LIKE 'TT%' THEN 1 ELSE 0 END) AS TT_All,
SUM(CASE WHEN visitepi.vaccinecode LIKE 'RB%' THEN 1 ELSE 0 END) AS RB_All 
FROM visitepi
LEFT JOIN person ON visitepi.pid = person.pid AND visitepi.pcucodeperson = person.pcucodeperson
LEFT JOIN house ON person.pcucodeperson = house.pcucode AND person.hcode = house.hcode
LEFT JOIN village ON village.pcucode = house.pcucode AND village.villcode = house.hcode 
WHERE visitepi.dateepi BETWEEN '2013-04-01' and '2013-04-30'
GROUP BY house.villcode
#lung1969
UNION
SELECT 
'รวมใช้วัคซีน(dose)',
SUM(CASE WHEN visitepi.vaccinecode LIKE 'DHB%' THEN 1 ELSE 0 END) AS DHB_All,
SUM(CASE WHEN visitepi.vaccinecode LIKE 'DTP%' THEN 1 ELSE 0 END) AS DTP_All, 
SUM(CASE WHEN visitepi.vaccinecode LIKE 'OPV%' THEN 1 ELSE 0 END) AS OPV_All,
SUM(CASE WHEN visitepi.vaccinecode = 'MMR' THEN 1 ELSE 0 END) AS MMR, 
SUM(CASE WHEN visitepi.vaccinecode LIKE 'JE%' THEN 1 ELSE 0 END) AS JE_All,
SUM(CASE WHEN visitepi.vaccinecode LIKE 'TT%' THEN 1 ELSE 0 END) AS TT_All,
SUM(CASE WHEN visitepi.vaccinecode LIKE 'RB%' THEN 1 ELSE 0 END) AS RB_All 
FROM visitepi
LEFT JOIN person ON visitepi.pid = person.pid AND visitepi.pcucodeperson = person.pcucodeperson
LEFT JOIN house ON person.pcucodeperson = house.pcucode AND person.hcode = house.hcode
LEFT JOIN village ON village.pcucode = house.pcucode AND village.villcode = house.hcode 
WHERE visitepi.dateepi BETWEEN '2015-08-01' and '2015-08-30';