SELECT
visitepi.pid AS PID,
concat(ctitle.titlename,person.fname,' ',person.lname) AS 'ชื่อ-สกุล',
getAgeYearNum(person.birth,CURDATE()) AS 'อายุ',
house.hno AS 'บ้านเลขที่',
village.villno AS 'หมู่ที่',
visitepi.dateepi AS 'วันที่ฉีดวัคซีน',
visitepi.pcucode AS 'สถานบริการที่ฉีดวัคซีน',
visitepi.vaccinecode AS 'รหัสวัคซีน'
FROM
person
INNER JOIN house ON person.pcucodeperson = house.pcucode AND person.hcode = house.hcode
INNER JOIN village ON house.pcucode = village.pcucode AND house.villcode = village.villcode
INNER JOIN visitepi ON visitepi.pcucodeperson = person.pcucodeperson AND visitepi.pid = person.pid
INNER JOIN ctitle ON ctitle.titlecode = person.prename
WHERE vaccinecode='MMRS'
#AND RIGHT(village.villcode,2)<> '00' 
and person.pid not in (select persondeath.pid from persondeath) 
and visitepi.dateepi BETWEEN '20150401' and '20150831';
GROUP BY person.pid;
----------------------------------------------------------------------------
SELECT COUNT(pid)
FROM visitepi
WHERE vaccinecode='MMRS'
AND dateepi BETWEEN '2014-07-01' AND '2014-08-31';