select
concat(pt.pname,pt.fname," ",pt.lname) as fullname,
concat(pt.addrpart," ËÁÙè ",pt.moopart," µ.",t3.name," Í.",t2.name," ¨.",t1.name) as fulladdressname,
op.an,icode,qty,year(rxdate)-year(birthday) as age,rxdate,order_no
from ovst ov
left outer join patient pt on pt.hn=ov.hn
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
left outer join opitemrece op on op.hn=ov.hn
where op.rxdate between "2007-01-01" and "2007-01-01" and op. icode ="1490006"
ตรง icode นี้เปลี่ยนตามรหัสของยาmorphine ของท่านเองครับ
group by order_no
order by rxdate