SELECT
person.pid
,concat(ctitle.titlename,person.fname,' ',person.lname) as 'ชื่อ-สกุล'
,getageymd(person.birth,CURDATE()) AS 'อายุ(ปี,เดือน,วัน)'
,concat(substr(person.birth,9,2),'/',substr(person.birth,6,2),'/',substr(person.birth,1,4)+543) as 'วันเกิด'
,person.idcard as CID
FROM
person
LEFT JOIN ctitle ON ctitle.titlecode = person.prename
where getAgeYearNum(person.birth,CURDATE()) <6
and typelive in (0,1,3)
and concat(person.pcucodeperson,person.pid) not in (SELECT concat(pcucodeperson,pid)FROM visitepi where vaccinecode in ('BCG','BCGs1'))
GROUP BY person.pid
ORDER BY person.mumoi,person.hnomoi;