select
p.pid,concat(ctitle.titlename,p.fname,' ',p.lname)as 'ชื่อ-สกุล'
,concat(substr(p.birth,9,2),'/',substr(p.birth,6,2),'/',substr(p.birth,1,4)+543)as'วันเกิด'
,GetAgeYearNum(p.birth,'2014-10-01') as 'อายุ'
,p.idcard as idcard
,house.hno 'บ้านเลขที่'
,SUBSTRING(house.villcode,7,2) as 'หมู่'
from person p
left join ctitle on p.prename = ctitle.titlecode
inner join house on p.pcucodeperson = house.pcucode and p.hcode = house.hcode
where CONCAT(p.pid,p.pcucodeperson) NOT IN (select CONCAT(persondeath.pid,persondeath.pcucodeperson)from persondeath)
and SUBSTRING(house.villcode,7,2) <> '00' and p.typelive in ('1','3') and GetAgeYearNum(p.birth,'2014-10-01')>='35'
and p.pid not in (select pid from personchronic where (personchronic.chroniccode='I10' or personchronic.chroniccode between 'E10' and 'E15.9'))
group by p.pid
order by house.villcode,house.hno;