BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Bluebird ที่ กันยายน 06, 2011, 14:18:57 PM

หัวข้อ: กรองผู้ป่วย admit ที่ถูกจำหน่าย ในเวลาราชการ และนอกเวลาราชการ
เริ่มหัวข้อโดย: Bluebird ที่ กันยายน 06, 2011, 14:18:57 PM
หากกรองผู้ป่วย admit  ในเวลาราชการ และนอกเวลาราชการ จะใช้
select count(i.an) as an from ipt i
left outer join an_stat a on a.an=i.an
left outer join ovst o on o.vn=a.vn
where i.regdate between "2010-10-01" and "2010-10-31"
and o.visit_type="I"


กรองผู้ป่วย admit ที่ถูกจำหน่าย ในเวลาราชการ และนอกเวลาราชการ

ในเวลา เวรเช้า
select count(i.an) as an from ipt i
left outer join an_stat a on a.an=i.an
left outer join ovst o on o.vn=a.vn
where i.dchdate between "2010-10-01" and "2010-10-31"
and i.dchtime between "08:00:00" and "16:00:00"
and i.dchdate not in (select h.holiday_date from holiday h where h.holiday_date between "2010-10-01" and "2010-10-31"" )

นอกเวลา เวรเช้า
select count(i.an) as an from ipt i
left outer join an_stat a on a.an=i.an
left outer join ovst o on o.vn=a.vn
where i.dchdate between "2010-10-01" and "2010-10-31"
and i.dchtime between "08:00:00" and "16:00:00"
and i.dchdate in (select h.holiday_date from holiday h where h.holiday_date between "2010-10-01" and "2010-10-31"" )