ที่มา บัญชี 2
ข้อมูล A จำนวนมารดาหลังคลอดได้รับการดูแลครบ 3 ครั้งตามเกณฑ์ ในเวลาที่กำหนด
select count(distinct p1.person_anc_id) from person_anc p1,person p2
where p1.person_id = p2.person_id
and p1.person_anc_id in (select person_anc_id from person_anc_preg_care where
person_anc_preg_care.person_anc_id = p1.person_anc_id and
person_anc_preg_care.preg_care_number = 1 and datediff(person_anc_preg_care.care_date,p1.labor_date) <= 7)
and p1.person_anc_id in (select person_anc_id from person_anc_preg_care where
person_anc_preg_care.person_anc_id = p1.person_anc_id and
person_anc_preg_care.preg_care_number = 2 and datediff(person_anc_preg_care.care_date,p1.labor_date) between 8 and 15 )
and p1.person_anc_id in (select person_anc_id from person_anc_preg_care where
person_anc_preg_care.person_anc_id = p1.person_anc_id and
person_anc_preg_care.preg_care_number = 3 and datediff(person_anc_preg_care.care_date,p1.labor_date) between 16 and 42 )
and p1.labor_date between 'yyyy-mm-dd1' and 'yyyy-mm-dd2'
and p1.labor_hospcode = 'xxxxx'
ข้อมูล B จำนวนมารดาที่คลอดในช่วงเวลาเดียวกัน
select count(distinct p1.person_anc_id) from person_anc p1,person p2
where p1.person_id = p2.person_id
and p1.labor_date between 'yyyy-mm-dd1' and 'yyyy-mm-dd2'
and p1.labor_hospcode = 'xxxxx'