select
concat(pt.pname,pt.fname," ",pt.lname) as fullname,ov.vn,ov.hn,
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-07-01" and "2007-07-31" and op.icode ="1000196"
group by rxtime
order by rxdate
รายงาน เปลี่ยน icode นะครับ