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
,CONCAT(person.hnomoi," ม.",person.mumoi) AS ' ที่อยู่'
FROM
person
LEFT JOIN ctitle ON ctitle.titlecode = person.prename
INNER JOIN house ON house.pcucode = person.pcucodeperson AND house.hcode = person.hcode
where person.sex = '2'
AND getAgeYearNum(person.birth,CURDATE()) BETWEEN 30 AND 60
and typelive in (0,1,3)
AND SUBSTRING(house.villcode,7,2)<>'00' 
and concat(person.pcucodeperson,person.pid) not in (SELECT concat(pcucodeperson,pid)FROM visitlabcancer where visitlabcancer.typecancer = '2' )
GROUP BY person.pid
ORDER BY person.mumoi*1,person.hnomoi;