ลองคิวรี่นี่ดู
select v.village_moo,v.village_name
,count(distinct p.person_id) cc
,count(distinct if(pv1.export_vaccine_code="073"
or pv2.export_vaccine_code="073",p.person_id,null)) mmr
from village v
left join person p on v.village_id=p.village_id
left join person_vaccine_list pl on p.person_id=pl.person_id
left join person_vaccine pv1 on pv1.person_vaccine_id=pl.person_vaccine_id
left join (select o.hn,ov.person_vaccine_id from ovst o
join ovst_vaccine ov on ov.vn=o.vn) ov on ov.hn=p.patient_hn
left join person_vaccine pv2 on pv2.person_vaccine_id=ov.person_vaccine_id
where v.village_moo<>0
and p.birthdate between "2008-06-01" and "2012-01-31"
and p.house_regist_type_id in (1,2,3) /*ไม่แน่ใจบ้านว่าแค่ 1,3 รึป่าว*/
and p.death<>"Y"
group by v.village_moo
order by cast(v.village_moo as signed)
เพราะอาจจับแค่ ovst_vaccine ยังขาด person_vaccine_list รึป่าว