BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: yukiplee ที่ มกราคม 30, 2013, 08:53:25 AM

หัวข้อ: จำนวนเวชระเบียนรายใหม่
เริ่มหัวข้อโดย: yukiplee ที่ มกราคม 30, 2013, 08:53:25 AM
จะหา จำนวนเวชระเบียนผู้ป่วย OPD รายใหม่ที่มีการซักและบันทึกประวัติการสูบบุหรี่ อย่างไรบ้างครับ ขอคำแนะนำด้วยครับ เพื่อจะดูว่า จำนวนโอพีดีการ์ดรายใหม่ทั้งหมดกี่คน และมีการซักเรื่องการสูบบุหรี่ กี่คน(เดือนตุลาคม)
ถ้าแสดงเป็นรายฃื่อ ยิ่งดีคับ
หัวข้อ: Re: จำนวนเวชระเบียนรายใหม่
เริ่มหัวข้อโดย: jameborn ที่ มกราคม 30, 2013, 15:44:41 PM
select count(distinct v.vn) 'Total'
,count(distinct if(v.count_in_year=0,v.vn,null)) 'New'
,count(distinct if(s.smoking_type_id is not null,s.vn,null)) 'Smoking'
,count(distinct if(s.smoking_type_id is not null and v.count_in_year=0,s.vn,null)) 'New_Smoking'
,count(distinct if(s.drinking_type_id is not null,s.vn,null)) 'Drinking'
,count(distinct if(s.drinking_type_id is not null and v.count_in_year=0,s.vn,null)) 'New_Drinking'
from vn_stat v
left join opdscreen s on v.vn=s.vn
where v.vstdate between '2012-10-1' and '2012-10-31'
ลองดู
หัวข้อ: Re: จำนวนเวชระเบียนรายใหม่
เริ่มหัวข้อโดย: jameborn ที่ มกราคม 30, 2013, 15:49:58 PM
select v.vn,v.hn,pt.pname,pt.fname,pt.lname,v.vstdate
,s.smoking_type_id,st.smoking_type_name
from vn_stat v
left join patient pt on pt.hn=v.hn
left join opdscreen s on s.vn=v.vn
left join smoking_type st on st.smoking_type_id=s.smoking_type_id
where v.vstdate between '2012-10-1' and '2012-10-31'
and v.count_in_year=0
and s.smoking_type_id is not null
order by s.smoking_type_id