select v.vn,v.hn as HN,pt.cid,v.vstdate,concat(pt.pname,pt.fname," ",pt.lname) as Name,
v.age_y,pt.addrpart,pt.moopart,t3.name,concat(pt.pttype,"-",p1.name) pts,concat(pt.addrpart," ?.",pt.moopart," ?.",t3.name," ?.",t2.name," ?.",t1.name) as Address,
v.lastvisit,o.bps,o.bpd,o.bw,o.height ,l3.lab_items_name,l2.lab_order_result,op.icode,dr.name,op.qty,d1.name1
from vn_stat v
left outer join patient pt on pt.hn=v.hn
left outer join lab_head lh on lh.hn=v.hn
left outer join lab_order l2 on l2.lab_order_number=lh.lab_order_number
left outer join lab_items l3 on l3.lab_items_code=l2.lab_items_code
left outer join opitemrece op on op.hn=v.hn
left outer join drugitems dr on dr.icode = op.icode
left outer join drugusage d1 on d1.drugusage=op.drugusage
left outer join opdscreen o on o.hn=pt.hn
left outer join pttype p1 on p1.pttype=pt.pttype
left outer join thaiaddress t1 on t1.chwpart=pt.chwpart and t1.amppart="00" and t1.tmbpart="00"
left outer join thaiaddress t2 on t2.chwpart=pt.chwpart and t2.amppart=pt.amppart and t2.tmbpart="00"
left outer join thaiaddress t3 on t3.chwpart=pt.chwpart and t3.amppart=pt.amppart and t3.tmbpart=pt.tmbpart
where v.vstdate between "2012-04-01" and "2012-04-01" and l2.lab_order_result between 50 and 100
and v.hn in(select hn from clinicmember where clinic ="001")
and op.icode="1440028"
group by v.vn
order by v.vn
1440028 = รหัส ยา Enarapril