SELECT
person.pid,
concat(ctitle.titlename,person.fname,' ',person.lname)as 'ชื่อ-สกุล',
concat(substr(person.birth,9,2),'/',substr(person.birth,6,2),'/',substr(person.birth,1,4)+543) AS 'วันเกิด',
getagemonth(person.birth,CURDATE()) AS 'อายุ(เดือน)',
GetAgeYearNum(person.birth,CURRENT_DATE)as 'อายุ(ปี)',
person.hnomoi AS 'บ้านเลขที่',
person.mumoi AS 'หมู่ที่',
person.typelive
FROM person 
inner join ctitle on person.prename = ctitle.titlecode
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
LEFT JOIN persondeath ON person.pid=persondeath.pid
WHERE persondeath.pid IS NULL
AND  (person.dischargetype is null or person.dischargetype = 9) 
and SUBSTRING(house.villcode,7,2) !='00'
and person.typelive in ('0','1','3') 
AND getagemonth(person.birth,CURDATE()) IN (9,18,30,42 )
group by person.pid
order by person.mumoi;
#create by rambo