select vn.hcode,pt.cid,vn.hn,vn.vstdate,op.bmi,st.smoking_type_name,op.cc,vn.pdx,ot.icode,d.name
from vn_stat vn
left outer join patient pt on vn.hn = pt.hn
left outer join opdscreen op on vn.hn = op.hn
left outer join smoking_type st on op.smoking_type_id = st.smoking_type_id
left outer join opitemrece ot on vn.vn = ot.vn
left outer join drugitems d on ot.icode = d.icode
left outer join drugitems d1 on ot.icode = d1.icode
left outer join drugitems d2 on ot.icode = d2.icode
where vn.vstdate between '2012-01-01' and '2012-01-31'
and (vn.pdx in ('j459','j449','j441','j46')
or vn.dx0 in ('j459','j449','j441','j46')
or vn.dx1 in ('j459','j449','j441','j46')
or vn.dx2 in ('j459','j449','j441','j46')
or vn.dx3 in ('j459','j449','j441','j46')
or vn.dx4 in ('j459','j449','j441','j46')
or vn.dx5 in ('j459','j449','j441','j46'))
and ot.icode in("1000217","1520011","1000508")
group by vn.vn
ที่ต้องการเป็นแบบนี้หรือเปล่าครับ