BMS-HOSxP Community
HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Bluebird ที่ กรกฎาคม 14, 2015, 16:33:45 PM
-
เภสัช ต้องการ Script SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชีต่อ จำนวนรายการยาทั้งหมด
-
ลองแบบนี้ครับ
select sum(if(drugaccount<>'',1,0)) as ED, sum(if(drugaccount='',1,0)) as NED, count(*) as Total
from drugitems where istatus='Y'
-
ขอโทษครับ โจทย์ ไม่ชัดเจน
ต้องการ Script SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชี ต่อ จำนวนรายการยาที่ถูกสั่งใช้ทั้งหมดของผู้ป่วยนอก แต่ล่ะเดือน
-
จาก Query
select o.rxdate,count(o.icode) as icode_count
from opitemrece o
left outer join drugitems d on d.icode=o.icode
where o.rxdate between '2014-10-01' and '2014-10-31'
and o.an is null
and o.icode like '1%'
and d.drugaccount<>''
group by rxdate
ได้แค่ จำนวนรายการยาในบัญชีที่ถูกสั่งจ่ายแต่ล่ะวัน แต่ ต้องการให้ แสดง คอลัมบ์ ของจำนวนรายการยาทั้งหมดที่ถูกสั่งแต่ละวัน เพิ่มมาอีกช่อง
-
select o.rxdate,count(o.icode) All_Drug
,sum(d.drugaccount<>'' or d.drugaccount is not null) NED_Drug
from opitemrece o
join drugitems d on d.icode=o.icode
where o.rxdate between '2014-10-01' and '2014-10-31'
and o.an is null
group by rxdate
-
select o.rxdate,count(o.icode) All_Drug
,sum(d.drugaccount<>'' or d.drugaccount is not null) NED_Drug
from opitemrece o
join drugitems d on d.icode=o.icode
where o.rxdate between '2014-10-01' and '2014-10-31'
and o.an is null
group by rxdate
น่าจะเป็น ED_Drug ครับ