ลองคำสั่งประมาณนี้
select p.person_id,p.cid,p.patient_hn,p.pname,p.fname,p.lname
,s.service_date,s.body_weight,s.height
,ifnull((select 'X' from person_wbc_vaccine_detail d
where d.person_wbc_service_id=s.person_wbc_service_id
and d.wbc_vaccine_id in (1,2)),' ') 'BCG'
,ifnull((select 'X' from person_wbc_vaccine_detail d
where d.person_wbc_service_id=s.person_wbc_service_id
and d.wbc_vaccine_id in (7,8,9,10,11)),' ') 'DTP'
,ifnull((select 'X' from person_wbc_vaccine_detail d
where d.person_wbc_service_id=s.person_wbc_service_id
and d.wbc_vaccine_id in (39,40,41)),' ') 'DTP_HB'
,ifnull((select 'X' from person_wbc_vaccine_detail d
where d.person_wbc_service_id=s.person_wbc_service_id
and d.wbc_vaccine_id in (20,21,22,23,24)),' ') 'OPV'
,ifnull((select 'X' from person_wbc_vaccine_detail d
where d.person_wbc_service_id=s.person_wbc_service_id
and d.wbc_vaccine_id in (12,13,14)),' ') 'HB'
,ifnull((select 'X' from person_wbc_vaccine_detail d
where d.person_wbc_service_id=s.person_wbc_service_id
and d.wbc_vaccine_id in (15,16,17)),' ') 'JE'
,ifnull((select 'X' from person_wbc_vaccine_detail d
where d.person_wbc_service_id=s.person_wbc_service_id
and d.wbc_vaccine_id in (19)),' ') 'MMR'
from person p
left join person_wbc wbc on wbc.person_id=p.person_id
left join person_wbc_service s on wbc.person_wbc_id=s.person_wbc_id
where s.service_date between '2010-1-1' and '2010-1-31'
group by vn
order by p.person_id,vn