SELECT
person.pid,
person.idcard,
ctitle.titlename,
person.fname,
person.lname,
CONCAT(DATE_FORMAT(person.birth,'%d-%m-'),DATE_FORMAT(person.birth,'%Y')+543)as วันเกิด,
getAgeYearNum(person.birth,('2014-12-31')) AS age,
house.hno, right((house.villcode),2) AS moo
FROM person
INNER JOIN house ON person.hcode = house.hcode
INNER JOIN ctitle ON person.prename = ctitle.titlecode
LEFT JOIN persondeath ON person.pid = persondeath.pid
WHERE
2014-DATE_FORMAT(person.birth,'%Y') IN (30,35,40,45,50,55,60)
AND person.sex IN ('2')
AND persondeath.pid IS NULL
AND person.typelive in ('1','3')
AND right((house.villcode),2) != 00
ORDER BY moo,hno,age;