BMS-HOSxP Community
HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: Guitar-hero ที่ พฤศจิกายน 02, 2011, 15:07:49 PM
-
คือผมอยากทราบว่า รายการยา ที่ใช้จ่ายคนไข้ในแต่ละเดือนว่ามีการจ่ายไปรวมเป็นเงินเท่าไหร่ แยกผู้ป่วย OPD และ IPD เพื่อที่จะหามูลค่าการใช้ยา ยกตัวอย่างเช่น
รายการยา มูลค่าการใช้ OPD มูลค่าการใ้ช้ IPD
Paracetamol 10,000 15,000
xxxx xxxx xxxx
ไม่ทราบว่าต้องเขียนคำสั่ง sql ยังไงครับ
-
select px.icode,d.name
,sum(if(length(px.vn)>9,px.qty,0)) 'OPD_Qty'
,sum(if(length(px.vn)>9,px.sum_price,0)) 'OPD_Price'
,sum(if(length(px.vn)>9,0,px.qty)) 'IPD_Qty'
,sum(if(length(px.vn)>9,0,px.sum_price)) 'IPD_Price'
from opitemrece px
left join drugitems d on px.icode=d.icode
where px.vstdate between '2011-1-1' and '2011-1-1'
and d.name is not null
group by px.icode
order by px.icode