select person.pid AS HN
,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 'วันเดือนปีเกิด'
,YEAR(FROM_DAYS(DATEDIFF(CURDATE(),person.birth))) as 'อายุ'
,person.idcard as CID,house.hno as 'บ้านเลขที่'
,village.villno AS 'mu'
,if(person.candobedhomesocial=1,'/',null)as 'ติดสังคม'
,if(person.candobedhomesocial=2,'/',null)as 'ติดบ้าน'
,if(person.candobedhomesocial=3,'/',null)as 'ติดเตียง'
FROM person
INNER JOIN house ON person.hcode = house.hcode AND person.pcucodeperson = house.pcucode
INNER JOIN village ON house.villcode = village.villcode AND house.pcucode = village.pcucode
LEFT JOIN ctitle ON person.prename = ctitle.titlecode
WHERE YEAR(FROM_DAYS(DATEDIFF(CURDATE(),person.birth)))>=60
and right(village.villcode,2)<> '00' 
and person.typelive in (0,1,3)
and person.dischargetype=9
GROUP BY person.pid
ORDER BY Mu,Hno*1;