เอา โค้ด ที่เขียนมาให้ดูด้วยครับ
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,cid
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-02-01" and "2007-02-28" and op. icode ="1480756"
group by order_no
order by rxdate