Code พฤติกรรมสุขภาพ จากการคัดกรอง ncdscreen


select 
case when age_year between '15' and '34' then 'อายุ15_34'
when age_year between '35' and '59' then 'อายุ35_59'
when age_year >= '60' then 'อายุ>60'else null end as 'Grpage',
sum(case when alcohol = 1 then 1 else 0 end) as 'ไม่ดื่ม',
sum(case when alcohol = 2 then 1 else 0 end) as 'ดื่มนานๆครั้ง',
sum(case when alcohol = 3 then 1 else 0 end) as 'ดื่มเป็นครั้งคราว',
sum(case when alcohol = 4 then 1 else 0 end) as 'ดื่มเป็นประจำ',
sum(case when alcohol = 9 then 1 else 0 end) as 'ไม่ทราบ',
sum(case when smoke = 1 then 1 else 0 end) as 'ไม่สูบ',
sum(case when smoke = 2 then 1 else 0 end) as 'สูบนานๆครั้ง',
sum(case when smoke = 3 then 1 else 0 end) as 'สูบเป็นครั้งคราว',
sum(case when smoke = 4 then 1 else 0 end) as 'สูบประจำ',
sum(case when smoke = 9 then 1 else 0 end) as 'ไม่ทราบ'
from ncd_person_ncd_screen
where age_year >= '15' and concat(ncd_person_ncd_screen.pid,ncd_person_ncd_screen.pcucode)
not in (select concat(persondeath.pid,persondeath.pcucodeperson) from persondeath
where persondeath.pcucodeperson=ncd_person_ncd_screen.pcucode and (persondeath.deaddate is null or persondeath.deaddate<=curdate()))
and screen_date between '2013-10-01' and '2014-09-30'
group by Grpage