select
person.pid as pid,person.typelive as 'สถานะการอยู่อาศัย',substring(house.villcode,7,2)as 'หมู่บ้าน',n.screen_date as 'วันที่คัดกรอง'
from person
inner join house on person.pcucodeperson = house.pcucode and person.hcode = house.hcode
inner join village on house.pcucode = village.pcucode and village.villcode = house.villcode
inner join ncd_person_ncd_screen n on person.pid = n.pid
where person.typelive not in ('1','3') and person.pid not in (select persondeath.pid from persondeath)
and GetAgeYearNum(person.birth,'2015-10-01')>= '35'
and n.screen_date between '2015-10-01' and '2016-09-30'
group by person.pid
ORDER BY n.screen_date;