เอาคำสั่ง ไปลองดึงดูเล่นๆครับ
select o.hn,pws.vn,ps.person_id as false_person_id,ps.cid as person_cid,ps1.person_id as true_person_id,p.cid as patient_cid,
pw.vaccine_bcg_date,pw.vaccine_hbv1_date,pw.baby_service1_date ,pw.baby_service2_date
from person_wbc pw
left outer join person ps on ps.person_id = pw.person_id
left outer join person_wbc_service pws on pws.person_wbc_id=pw.person_wbc_id and pw.baby_service1_date=pws.service_date
left outer join ovst o on o.vn=pws.vn
left outer join patient p on p.hn=o.hn
left outer join person ps1 on p.cid=ps1.cid
where pw.vaccine_bcg_date between 20101001 and 20101031
and ps.cid<>p.cid