BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Bluebird ที่ กรกฎาคม 14, 2015, 16:33:45 PM

หัวข้อ: SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชีต่อ จำนวนรายการยาทั้งหมด
เริ่มหัวข้อโดย: Bluebird ที่ กรกฎาคม 14, 2015, 16:33:45 PM
เภสัช ต้องการ Script SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชีต่อ จำนวนรายการยาทั้งหมด
หัวข้อ: Re: SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชีต่อ จำนวนรายการยาทั้งหมด
เริ่มหัวข้อโดย: udomchok ที่ กรกฎาคม 14, 2015, 19:34:25 PM
ลองแบบนี้ครับ
select sum(if(drugaccount<>'',1,0)) as ED, sum(if(drugaccount='',1,0)) as NED, count(*) as Total
from drugitems where istatus='Y'
หัวข้อ: Re: SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชีต่อ จำนวนรายการยาทั้งหมด
เริ่มหัวข้อโดย: Bluebird ที่ กรกฎาคม 15, 2015, 10:00:39 AM
ขอโทษครับ โจทย์ ไม่ชัดเจน
ต้องการ Script SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชี ต่อ จำนวนรายการยาที่ถูกสั่งใช้ทั้งหมดของผู้ป่วยนอก แต่ล่ะเดือน
หัวข้อ: Re: SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชีต่อ จำนวนรายการยาทั้งหมด
เริ่มหัวข้อโดย: Bluebird ที่ กรกฎาคม 15, 2015, 10:27:42 AM
จาก 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

ได้แค่ จำนวนรายการยาในบัญชีที่ถูกสั่งจ่ายแต่ล่ะวัน แต่ ต้องการให้ แสดง คอลัมบ์ ของจำนวนรายการยาทั้งหมดที่ถูกสั่งแต่ละวัน  เพิ่มมาอีกช่อง
หัวข้อ: Re: SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชีต่อ จำนวนรายการยาทั้งหมด
เริ่มหัวข้อโดย: woravet ที่ กรกฎาคม 15, 2015, 11:14:55 AM
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
หัวข้อ: Re: SQL ดึง อัตราส่วนระหว่าง จำนวนรายการยาในบัญชีต่อ จำนวนรายการยาทั้งหมด
เริ่มหัวข้อโดย: udomchok ที่ กรกฎาคม 16, 2015, 03:00:21 AM
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 ครับ