BMS-HOSxP Community

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

หัวข้อ: จำนวนผู้ป่วยหอบหืด
เริ่มหัวข้อโดย: yukiplee ที่ มกราคม 30, 2013, 14:10:30 PM
หาจำนวนผู้ป่วยหอบหืด Re admid ภายใน 28 วัน กี่คนราย พอจะมีวิธีหาอย่างไรบ้างคับ  อยากได้ sql คับ
หัวข้อ: Re: จำนวนผู้ป่วยหอบหืด
เริ่มหัวข้อโดย: k_toedkiets ที่ มกราคม 30, 2013, 14:21:39 PM
หาจำนวนผู้ป่วยหอบหืด Re admid ภายใน 28 วัน กี่คนราย พอจะมีวิธีหาอย่างไรบ้างคับ  อยากได้ sql คับ
ตามนี้ครับ
select a1.an,a1.hn,a1.pdx as pdx1,
s1.name as clinic1,a2.pdx as pdx2,s2.name as clinic2,a1.regdate,a2.regdate,a1.dchdate,a2.dchdate,a2.lastvisit,a1.age_y,count(a1.pdx) as ptco
from an_stat a1
left outer join an_stat a2 on a1.hn=a2.hn
left outer join patient p on p.hn=a1.hn
left outer join spclty s1 on s1.spclty=a1.spclty
left outer join spclty s2 on s2.spclty=a2.spclty
where a2.regdate between a1.regdate and (a1.dchdate+28) and a1.pdx = a2.pdx
and a1.vn<>a2.vn
and a1.dchdate between '2010-02-01' and '2012-09-30'
group by a1.pdx
order by ptco desc
limit 20
หัวข้อ: Re: จำนวนผู้ป่วยหอบหืด
เริ่มหัวข้อโดย: jameborn ที่ มกราคม 30, 2013, 15:35:26 PM
select count(distinct a.an) 'Total'
,count(distinct if(a.lastvisit<=28,a.an,null)) 'ReAdmit'
,count(distinct a1.an) 'Asthma'
,count(distinct if(a.lastvisit<=28 and a1.an is not null,a.an,null)) 'Re_Asthma'
,count(distinct a2.an) 'COPD'
,count(distinct if(a.lastvisit<=28 and a2.an is not null,a.an,null)) 'Re_COPD'
from an_stat a
left join (select an from iptdiag where icd10='J459') a1 on a1.an=a.an
left join (select an from iptdiag where icd10='J449') a2 on a2.an=a.an
where a.dchdate between '2011-10-1' and '2012-9-30'
แบบนี้ไหวมั๊ย
หัวข้อ: Re: จำนวนผู้ป่วยหอบหืด
เริ่มหัวข้อโดย: James011 ที่ มกราคม 30, 2013, 15:48:41 PM
แบบนี้ไม่รู้ได้ป่าวครับ