คำสั่ง SQL
select d.icode,d.name as drug,d.units,d.strength
,sum(if(o2.icd10='w0099',o1.qty,0)) as 'W0099'
,sum(if(o2.icd10='w9999',o1.qty,0)) as 'W9999'
,sum(if(o2.icd10='a09',o1.qty,0)) as 'A09'
,sum(if(o2.icd10='j039',o1.qty,0)) as 'J039'
,sum(if(o2.icd10='j069',o1.qty,0)) as 'J069'
,sum(if(o2.icd10='j00',o1.qty,0)) as 'J00'
,sum(if(o2.icd10='j029',o1.qty,0)) as 'j029'
from drugitems d
left join opitemrece o1 on o1.icode=d.icode
left join ovstdiag o2 on o1.vn=o2.vn
where o1.vstdate between '2009-1-1' and '2009-1-31'
group by d.icode
order by d.name
แบบนี้ไวมั๊ย เปลี่ยนช่วงเดือนเอาหล่ะกันคับ