SELECT
CONCAT(ctitle.titlename,' ',person.fname,' ',person.lname) AS `ชื่อ - นามสกุล`,
person.idcard AS '13 หลัก',
CONCAT(DATE_FORMAT(person.birth,'%d/%m/'),DATE_FORMAT(person.birth,'%Y')+543) AS `วันเกิด`,
getAgeYearNum(person.birth,CURDATE()) AS `อายุ(ปี)`,
CONCAT(person.hnomoi,' ','หมู่ที่',' ',person.mumoi) AS `ที่อยู่`,
cright.rightname AS 'สิทธิบัตร'
FROM house
INNER JOIN person ON house.hcode = person.hcode
INNER JOIN village ON house.villcode = village.villcode
INNER JOIN ctitle ON person.prename = ctitle.titlecode
INNER JOIN cright ON cright.rightcode = person.rightcode
WHERE getAgeYearNum(person.birth,CURDATE()) BETWEEN '35' AND '140'
AND ((person.dischargetype is null) OR (person.dischargetype != '1'))
AND village.villno <>'0'
AND person.typelive in ('1','3')
ORDER BY mumoi,hnomoi*1;