BMS-HOSxP Community
HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: vinaisena ที่ พฤษภาคม 10, 2011, 09:32:05 AM
-
select pt.*,ov.*
from an_stat ov ,patient pt ,ipt ovst
where ov.an=ovst.an and ov.dchdate between "2009-10-01" and "2010-09-30" and ov.hn=pt.hn
and ov.age_y>= 0
and ov.age_y<= 200
จากคำสั่งนี้ เราจะหาว่า โรคใดบ้าง 10 อันดับที่มี op1='9672' หรือ '9671' จะเพิ่มเติมคำสั่งอะไรบ้างครับ ท่านอาจารย์
-
น่าจะเอา iptdiag มาอีกสักตารางครับ...เอาเป็น where ov.an in (select an from iptdiag where icd10 in ("9672,"9671"))
-
select a.pdx,count(*) cc
from an_stat a
left join iptoprt iop on iop.an=a.an
where a.dchdate between '2009-10-01' and '2010-09-30'
and iop.icd9 in ('9672','9671')
group by a.pdx
order by cc desc
limit 10
ประมาณนี้มั๊ยคับ
-
select a.pdx,count(*) cc
from an_stat a
left join iptoprt iop on iop.an=a.an
where a.dchdate between '2009-10-01' and '2010-09-30'
and iop.icd9 in ('9672','9671')
group by a.pdx
order by cc desc
limit 10
ประมาณนี้มั๊ยคับ
ข้อสังเกตุของการใช้ SQL แบบนี้ คือ order by cc desc limit 10 แล้วถ้า cc ที่อันดับ 11 มันมีค่าเท่ากัน กับอันดับที่ 10 มันก็หายไปสิครับ
ผมสมมุติตัวอย่างข้อมูลนะครับที่พอเราจัดเรียงตาม cc แล้วได้ออกมาแบบนี้
pdx name cases
H259 Senile cataract, unspecified 10
J459 Asthma, unspecified 10
D569 Thalassaemia, unspecified 10
H813 Other peripheral vertigo 8
N10 Acute tubulo-interstitial nephritis 6
C189 Malignant neoplasm of colon, unspecified 6
L89 Decubitus ulcer 6
F209 Schizophrenia, unspecified 6
P599 Neonatal jaundice, unspecified 6
K922 Gastrointestinal haemorrhage, unspecified 6
I48 Atrial fibrillation and flutter 6
D619 Aplastic anaemia, unspecified 5
I471 Supraventricular tachycardia 5
K291 Other acute gastritis 5
ถ้ากำหนด limit 10 จะเหลือแค่
pdx name cases
H259 Senile cataract, unspecified 10
J459 Asthma, unspecified 10
D569 Thalassaemia, unspecified 10
H813 Other peripheral vertigo 8
N10 Acute tubulo-interstitial nephritis 6
C189 Malignant neoplasm of colon, unspecified 6
L89 Decubitus ulcer 6
F209 Schizophrenia, unspecified 6
P599 Neonatal jaundice, unspecified 6
K922 Gastrointestinal haemorrhage, unspecified 6
ใช่ไหมครับ
แล้ว I48 Atrial fibrillation and flutter 6 ก็น้อยใจแย่สิครับ นับได้ 6 เหมือนกัน แต่ไม่ได้อยู่ใน list
ซึ่งถ้าสรุปจากตัวอย่างที่ผมให้มาแล้ว จะได้แบบนี้ครับ
อันดับ 1 มี count เป็น 10 มี 3 โรค H259, J459, D569
อันดับ 2 มี count เป็น 8 มี 1 โรค H813
อันดับ 3 มี count เป็น 6 มี 7 โรค N10, C189, L89, F209, P599, K922, I48
อันดับ 4 มี count เป็น 5 มี 3 โรค D619, I471, K291
ลองหาแนวทางแก้ไขนะครับ
อ้อ...อันนี้ไม่เกี่ยวกับการใส่ท่อช่วยหายใจนะครับ ;D ;D ;D ;D
-
คำสั่งนี้ เป็นโรคที่พบบ่อย 20 อันดับ
ที่มีการใช้เครื่องช่วยหายใจ
รวมถึงมีการรวมวันนอน รพ.ด้วย
ฝาก อ.ช่วยตรวจสอบด้วยครับ
select v.pdx,count(v.pdx) as pdx_count, i.name as icdname,sum(v.admdate)
from an_stat v
left outer join icd101 i on i.code=v.pdx
left join iptoprt iop on iop.an=v.an
where v.dchdate between "2010-10-01" and "2011-03-31" and v.pdx is not null and v.pdx<>""
and iop.icd9 in ('9672','9671')
group by v.pdx,i.name
order by pdx_count desc
limit 20
-
คำสั่งนี้ เป็นโรคที่พบบ่อย 20 อันดับ
ที่มีการใช้เครื่องช่วยหายใจ
รวมถึงมีการรวมวันนอน รพ.ด้วย
ฝาก อ.ช่วยตรวจสอบด้วยครับ
select v.pdx,count(v.pdx) as pdx_count, i.name as icdname,sum(v.admdate)
from an_stat v
left outer join icd101 i on i.code=v.pdx
left join iptoprt iop on iop.an=v.an
where v.dchdate between "2010-10-01" and "2011-03-31" and v.pdx is not null and v.pdx<>""
and iop.icd9 in ('9672','9671')
group by v.pdx,i.name
order by pdx_count desc
limit 20
ถ้ามองผ่าน ๆ ก็ใช้ได้ครับ เพราะ limit 20 มันย่อมเอาข้อมูล 20 รายการแรกมาแสดงตามที่เราเรียงอยู่แล้ว
คำถามเดิมครับ หากลำดับที่ 21, 22 , .... มีจำนวน count(pdx) เท่ากับลำดับที่ 20 มันมิเสียใจแย่เหรอครับ ควรจะติดอันดับด้วยนะ
ลองเปลี่ยน sql อีกนิดครับ
-
นึกไม่ออก ครับ อาจารย์ บอกใบ้หน่อยซิ
-
ใช้ concept เดียวกับ http://hosxp.net/index.php?option=com_smf&Itemid=28&topic=20695.msg179052#msg179052 ครับ
คือ ผมจะ count มาก่อนว่า 20 อันดับแรกเนี่ยมีความถี่เท่าไร แล้วค่อยเอาความถี่ 20 อันดับนี้มาหาอีกทีว่ามีโรคอะไรบ้าง