ผู้เขียน หัวข้อ: อยากรบกวนให้ ช่วยเขียน SQL ให้หน่อยครับ  (อ่าน 7237 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ Apiruk_Jbhos

  • Sr. Member
  • ****
  • กระทู้: 386
  • Respect: +1
    • ดูรายละเอียด
    • โรงพยาบาล สมเด็จพระยุพราช จอมบึง
สวัสดีครับ พอดีที่ รพ.เขาอยากจะได้ 10 อันดับ โรค ของ ตำบล รายหมู๋ แต่ Code ที่เขียนมันเป็น รายครั้งครับ

select a.pdx,count(a.pdx) as pdx_count ,i.name as icdname,a.aid as aid ,a.moopart as moo
from vn_stat a
left outer join icd101 i on i.code=a.main_pdx
where a.vstdate between '2006-01-01' and '2010-03-12'
and a.pdx<>'' and a.pdx is not null
and a.aid = "700201"
and a.moopart = "1"
group by a.pdx,i.name
order by pdx_count desc
limit 10

ก็ออกมา เยอะหน่อย
แบบนี้ครับ
pdx   pdx_count   icdname
I10   1311   HT, Hypertension (Essential (primary))
Z480   1065   การดูแลติดตามทางศัลยกรรมอื่น
E119   654   Non-insulin-dependent diabetes mellitus
J029   570   Acute pharyngitis
Z501   191   การดูแลที่เกี่ยวข้องกับหัตถการฟื้นฟูสภาพ
K30   151   Dyspepsia
K029   143   Dental caries
Z242   134   ความต้องการการสร้างเสริมภูมิคุ้มกันต่อโรคติดเชื้อไวรัสโรคใดโรคหนึ่ง
K0402   117   Diseases of pulp and periapical tissues
Z300   110   การรับบริการคุมกำเนิด


แต่ อยากได้เป็น รายคน ครับ ประมาร ว่า ตัด HN ซ้ำออกครับ แต่ พอเอา HN ไปใส่ใน Group แล้วมัน ออกมา ผิดครับ
กลับออกมาแบบนี้ครับ
select a.pdx,count(a.pdx) as pdx_count ,i.name as icdname,a.aid as aid ,a.moopart as moo
from vn_stat a
left outer join icd101 i on i.code=a.main_pdx
where a.vstdate between '2006-01-01' and '2010-03-12'
and a.pdx<>'' and a.pdx is not null
and a.aid = "700201"
and a.moopart = "1"
group by a.pdx,i.name,a.hn
order by pdx_count desc
limit 10
ออกมาแบบนี้ครับ

pdx   pdx_count   icdname
Z480   93   การดูแลติดตามทางศัลยกรรมอื่น
Z501   41   การดูแลที่เกี่ยวข้องกับหัตถการฟื้นฟูสภาพ
I10   36   HT, Hypertension (Essential (primary))
I10   36   HT, Hypertension (Essential (primary))
I10   36   HT, Hypertension (Essential (primary))
I10   35   HT, Hypertension (Essential (primary))
Z480   35   การดูแลติดตามทางศัลยกรรมอื่น
B24   35   Unspecified human immunodeficiency virus(HIV) disease
I10   34   HT, Hypertension (Essential (primary))
I10   34   HT, Hypertension (Essential (primary))
ไงกรุณาช่วยดูให้หน่อยครับ
นาย อภิรักษ์ ชุ่มชะอุ่ม
Mail advance_pro@hotmail.com
โรงพยาบาล สมเด็จพระยุพราช จอมบึง

Server 1 : SR550 Ram 64G
OS1 : CentOS Linux 7.6
MariaDB version 10.1.19

Server 2 : IBM X3500 Ram 6G
OS2 : CentOS 7.6


ขึ้นระบบ เดือน กรกฎาคม 50
http://www.ChomBungHospital.com/

ออฟไลน์ redfireball

  • Full Member
  • ***
  • กระทู้: 219
  • คุณแม่ขอร้อง..ร้อง....
  • Respect: +4
    • ดูรายละเอียด
Re: อยากรบกวนให้ ช่วยเขียน SQL ให้หน่อยครับ
« ตอบกลับ #1 เมื่อ: มีนาคม 13, 2010, 02:57:18 AM »
0
set @d1 = '2010-01-01';
set @d2 = '2010-01-31';
select concat(t.name,' หมู่ ',a0.moopart) as tmb_moo
,(select a1.pdx from vn_stat a1 where a1.vstdate between @d1 and @d2 and a1.moopart = a0.moopart and a1.aid = a0.aid and (a1.pdx<>'' or a1.pdx is not null) group by a1.pdx order by count(*) desc, a1.pdx limit 1) as no1
,(select a2.pdx from vn_stat a2 where a2.vstdate between @d1 and @d2 and a2.moopart = a0.moopart and a2.aid = a0.aid and (a2.pdx<>'' or a2.pdx is not null) group by a2.pdx order by count(*) desc, a2.pdx limit 1,1) as no2
,(select a3.pdx from vn_stat a3 where a3.vstdate between @d1 and @d2 and a3.moopart = a0.moopart and a3.aid = a0.aid and (a3.pdx<>'' or a3.pdx is not null) group by a3.pdx order by count(*) desc, a3.pdx limit 2,1) as no3
,(select a4.pdx from vn_stat a4 where a4.vstdate between @d1 and @d2 and a4.moopart = a0.moopart and a4.aid = a0.aid and (a4.pdx<>'' or a4.pdx is not null) group by a4.pdx order by count(*) desc, a4.pdx limit 3,1) as no4
,(select a5.pdx from vn_stat a5 where a5.vstdate between @d1 and @d2 and a5.moopart = a0.moopart and a5.aid = a0.aid and (a5.pdx<>'' or a5.pdx is not null) group by a5.pdx order by count(*) desc, a5.pdx limit 4,1) as no5
,(select a6.pdx from vn_stat a6 where a6.vstdate between @d1 and @d2 and a6.moopart = a0.moopart and a6.aid = a0.aid and (a6.pdx<>'' or a6.pdx is not null) group by a6.pdx order by count(*) desc, a6.pdx limit 5,1) as no6
,(select a7.pdx from vn_stat a7 where a7.vstdate between @d1 and @d2 and a7.moopart = a0.moopart and a7.aid = a0.aid and (a7.pdx<>'' or a7.pdx is not null) group by a7.pdx order by count(*) desc, a7.pdx limit 6,1) as no7
,(select a8.pdx from vn_stat a8 where a8.vstdate between @d1 and @d2 and a8.moopart = a0.moopart and a8.aid = a0.aid and (a8.pdx<>'' or a8.pdx is not null) group by a8.pdx order by count(*) desc, a8.pdx limit 7,1) as no8
,(select a9.pdx from vn_stat a9 where a9.vstdate between @d1 and @d2 and a9.moopart = a0.moopart and a9.aid = a0.aid and (a9.pdx<>'' or a9.pdx is not null) group by a9.pdx order by count(*) desc, a9.pdx limit 8,1) as no9
,(select a10.pdx from vn_stat a10 where a10.vstdate between @d1 and @d2 and a10.moopart = a0.moopart and a10.aid = a0.aid and (a10.pdx<>'' or a10.pdx is not null) group by a10.pdx order by count(*) desc, a10.pdx limit 9,1) as no10
from vn_stat a0
left join thaiaddress t on a0.aid = t.addressid
where a0.aid = '430801' and a0.moopart in ('1','2','3','4','5','6')
and a0.vstdate between @d1 and @d2
group by a0.moopart;

แบบนี้ พอไหวไมครับ  ;D ;D ;D
« แก้ไขครั้งสุดท้าย: มีนาคม 13, 2010, 03:02:04 AM โดย redfireball »
โรงพยาบาลสังคม
SANGKHOM HOSPITAL
30 เตียง อ.สังคม จ.หนองคาย
http://www.sangkhomhospital.com
ขึ้นระบบ 5 ธ.ค. 51

ออฟไลน์ เกื้อกูล ครับ..

  • Hero Member
  • *****
  • กระทู้: 12,611
  • Respect: +169
    • ดูรายละเอียด
    • โรงพยาบาลปากท่อ
Re: อยากรบกวนให้ ช่วยเขียน SQL ให้หน่อยครับ
« ตอบกลับ #2 เมื่อ: มีนาคม 13, 2010, 08:42:41 AM »
0
แบบนี้ พอไหวไมครับ  ;D ;D ;D


อย่างนี้ เรียกว่า เยี่ยมครับ...ท่าน
Implement  HOSxP  Start 2548 ---> NOW!
Station : 130 Client   V.3 Version  3.67.1.XX
Server  : CENTOS  +MySQL maria 10.x.x

ออฟไลน์ E-Hos

  • Hero Member
  • *****
  • กระทู้: 711
  • Respect: 0
    • ดูรายละเอียด
    • http://www.erawanhospital.com/index.php
Re: อยากรบกวนให้ ช่วยเขียน SQL ให้หน่อยครับ
« ตอบกลับ #3 เมื่อ: มีนาคม 13, 2010, 08:53:44 AM »
0
แบบนี้ พอไหวไมครับ  ;D ;D ;D


อย่างนี้ เรียกว่า เยี่ยมครับ...ท่าน

สุดยอดครับ อ. ;D ;D ;D ;D
ACADEMIC COMPUTING.  Erawan_Hospital
>> Thanks ... DansaI HospitaL L-o-E-i
>> By อ. Decha, อ.Armds

=> NoW !! HosXP SERVER Version 3.58.1.1
=> Client 50 client  OS: SP2 >> 3.58.1.1
=> ER Room  NoW ! HosXP Version 3.57.7.25D
=> Doctor Room  NoW ! HosXP Version 3.58.1.1
=> HosXP Test  Version 3.58.1.xx
=> Coming Soon >>UP Version 3.58.1.xx
wait...
-----------------------------
Start  System  8 January 2009

ออฟไลน์ udomchok

  • Hero Member
  • *****
  • กระทู้: 8,347
  • Respect: +589
    • ดูรายละเอียด
    • ร.พ.สมเด็จพระสังฆราช องค์ที่ 17
Re: อยากรบกวนให้ ช่วยเขียน SQL ให้หน่อยครับ
« ตอบกลับ #4 เมื่อ: มีนาคม 13, 2010, 11:34:49 AM »
0
สวัสดีครับ พอดีที่ รพ.เขาอยากจะได้ 10 อันดับ โรค ของ ตำบล รายหมู๋ แต่ Code ที่เขียนมันเป็น รายครั้งครับ

select a.pdx,count(a.pdx) as pdx_count ,i.name as icdname,a.aid as aid ,a.moopart as moo
from vn_stat a
left outer join icd101 i on i.code=a.main_pdx
where a.vstdate between '2006-01-01' and '2010-03-12'
and a.pdx<>'' and a.pdx is not null
and a.aid = "700201"
and a.moopart = "1"
group by a.pdx,i.name
order by pdx_count desc
limit 10

ก็ออกมา เยอะหน่อย
แบบนี้ครับ
pdx   pdx_count   icdname
I10   1311   HT, Hypertension (Essential (primary))
Z480   1065   การดูแลติดตามทางศัลยกรรมอื่น
E119   654   Non-insulin-dependent diabetes mellitus
J029   570   Acute pharyngitis
Z501   191   การดูแลที่เกี่ยวข้องกับหัตถการฟื้นฟูสภาพ
K30   151   Dyspepsia
K029   143   Dental caries
Z242   134   ความต้องการการสร้างเสริมภูมิคุ้มกันต่อโรคติดเชื้อไวรัสโรคใดโรคหนึ่ง
K0402   117   Diseases of pulp and periapical tissues
Z300   110   การรับบริการคุมกำเนิด


แต่ อยากได้เป็น รายคน ครับ ประมาร ว่า ตัด HN ซ้ำออกครับ แต่ พอเอา HN ไปใส่ใน Group แล้วมัน ออกมา ผิดครับ
กลับออกมาแบบนี้ครับ
select a.pdx,count(a.pdx) as pdx_count ,i.name as icdname,a.aid as aid ,a.moopart as moo
from vn_stat a
left outer join icd101 i on i.code=a.main_pdx
where a.vstdate between '2006-01-01' and '2010-03-12'
and a.pdx<>'' and a.pdx is not null
and a.aid = "700201"
and a.moopart = "1"
group by a.pdx,i.name,a.hn
order by pdx_count desc
limit 10
ออกมาแบบนี้ครับ

pdx   pdx_count   icdname
Z480   93   การดูแลติดตามทางศัลยกรรมอื่น
Z501   41   การดูแลที่เกี่ยวข้องกับหัตถการฟื้นฟูสภาพ
I10   36   HT, Hypertension (Essential (primary))
I10   36   HT, Hypertension (Essential (primary))
I10   36   HT, Hypertension (Essential (primary))
I10   35   HT, Hypertension (Essential (primary))
Z480   35   การดูแลติดตามทางศัลยกรรมอื่น
B24   35   Unspecified human immunodeficiency virus(HIV) disease
I10   34   HT, Hypertension (Essential (primary))
I10   34   HT, Hypertension (Essential (primary))
ไงกรุณาช่วยดูให้หน่อยครับ
ทำไมนับแต่ pdx ล่ะครับ
ถ้าคนไข้มารับการรักษา DM และ HT ในวันเดียวกัน แล้วเอา DM เป็น pdx ส่วน HT เป็น SDx อย่างนี้ก็หายสิครับ

น่าจะนับจาก ovstdiag จะดีกว่าไหมครับ
select o.icd10, count(o.vn) as cases, i.name
from ovstdiag o
join icd101 i on i.code=o.icd10
where .....
group by o.icd10
order by count(vn)

ถ้านับคนก็ count distinct
select o.icd10, count(distinct o.hn) as cases, i.name
from ovstdiag o
join icd101 i on i.code=o.icd10
where .....
group by o.icd10
order by count(vn)

ประมาณนี้ครับ (พอดียังไม่ได้ลอง run จริง ๆ นะครับ...โปรดระวัง...ด้นสด ๆ)
ทำด้วยหัวใจร.พ.สมเด็จพระสังฆราช องค์ที่ 17 อ.สองพี่น้อง จ.สุพรรณบุรี
อบรมโดย BMS Team เมื่อ พ.ย. 49 ขึ้นระบบห้องบัตรเมื่อ X'Mas 2007
2008 : X-Ray กายภาพบำบัด แพทย์แผนไทย กิจกรรมบำบัด OPD ตา
2009 : ทันตกรรม ห้องตรวจตา OPD (พยาบาลและห้องตรวจแพทย์บางห้อง)

ออฟไลน์ Bond_007

  • Hero Member
  • *****
  • กระทู้: 1,533
  • เมื่อก่อนเคยรักมากเท่าไหร่มันยังคงรักมากเท่านั้น
  • Respect: +2
    • ดูรายละเอียด
Re: อยากรบกวนให้ ช่วยเขียน SQL ให้หน่อยครับ
« ตอบกลับ #5 เมื่อ: มีนาคม 13, 2010, 13:56:40 PM »
0
 ;D :o :o
โรงพยาบาลศิริเวชลำพูน
Hosxp version 3.53.7.16
ขอขบคุณ อาจารย์ชัยพร,อ.อ็อด,อ.เกื้อ,พี่เอก,พี่กิติศักดิ์,พี่เข้ม,พี่ไสว,พี่ terminator 2010,พี่pikepid,พี่udomchock ,พี่ขวด,พี่เจมส์,ป๋าJdadmin,พี่กานดา admin ทุกๆท่าน และนางฟ้า BMS

ทำเพื่อใครสักคนฉันได้ทำเพื่อความรัก
ร้องให้สักคนฉันก็ร้องจากหัวใจ
รักที่มันต้องจบมันก็ยังงดงาม ฉันยังจำไว้

Nologo How to be hosxp star

ออฟไลน์ Svl2Nuk3

  • Hero Member
  • *****
  • กระทู้: 793
  • Respect: 0
    • ดูรายละเอียด
Re: อยากรบกวนให้ ช่วยเขียน SQL ให้หน่อยครับ
« ตอบกลับ #6 เมื่อ: มีนาคม 13, 2010, 20:49:12 PM »
0
ดูคร่าวๆ  ถ้าทำเป็น  cross tab  report  น่าจะง่ายกว่านะครับ
 ;D
I'm nuke (นุ๊ก)
My Blog  : http://www.codenuke.net
อดีต นวก.คอมฯ รพช.พรหมพิราม => 1 พ.ค. 52 - 30 ก.ย. 54
ปัจจุบัน : Software Engineer บริษัทแห่งหนึ่ง

doramon

  • บุคคลทั่วไป
Re: อยากรบกวนให้ ช่วยเขียน SQL ให้หน่อยครับ
« ตอบกลับ #7 เมื่อ: มีนาคม 13, 2010, 23:42:51 PM »
0
น่าจะนับจาก ovstdiag จะดีกว่าไหมครับ


ตารางนี้น่าจะดีถูกมากกว่า vn_stat