305
« เมื่อ: มิถุนายน 05, 2009, 15:08:45 PM »
select a.dx_doctor,dr.name,o.icode,concat(d.name,' ',d.strength) as drug
,d.units,d.unitprice,d.unitcost
,sum(if(month(o.vstdate)=1,o.qty,0)) as 'mo1'
,sum(if(month(o.vstdate)=2,o.qty,0)) as 'mo2'
,sum(if(month(o.vstdate)=3,o.qty,0)) as 'mo3'
,sum(if(month(o.vstdate)=4,o.qty,0)) as 'mo4'
,sum(if(month(o.vstdate)=5,o.qty,0)) as 'mo5'
,sum(if(month(o.vstdate)=6,o.qty,0)) as 'mo6'
,sum(if(month(o.vstdate)=7,o.qty,0)) as 'mo7'
,sum(if(month(o.vstdate)=8,o.qty,0)) as 'mo8'
,sum(if(month(o.vstdate)=9,o.qty,0)) as 'mo9'
,sum(if(month(o.vstdate)=10,o.qty,0)) as 'mo10'
,sum(if(month(o.vstdate)=11,o.qty,0)) as 'mo11'
,sum(if(month(o.vstdate)=12,o.qty,0)) as 'mo12'
,sum(o.qty) as qty
,sum(o.sum_price) as sum_price
from opitemrece o
left join drugitems d on o.icode=d.icode
left join an_stat a on o.an=a.an
left join doctor dr on a.dx_doctor=dr.code
where o.vstdate between '2008-1-1' and '2008-12-31'
and d.antibiotic='Y'
and left(a.pdx,1)='J'
group by a.dx_doctor,o.icode
order by a.dx_doctor,o.icode
ขอโทษทีคับ sum ผิดที่ เห็นได้ค่าเลยไม่ได้ตรวจสอบ
ลองดูคับผม
*****
ราคารวมผมว่าน่าจะเป็น unitprice มากกว่า unitcost นะคับ