ผู้เขียน หัวข้อ: ดู Code ผู้มารับบริการทันตกรรมให้หน่อยครับ  (อ่าน 3870 ครั้ง)

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

ออฟไลน์ prapansak

  • Full Member
  • ***
  • กระทู้: 232
  • Respect: 0
    • ดูรายละเอียด
    • http://118.175.76.8/bl/
Code ที่ใช้นำไปรันใน SQL hosxp ผ่านครับ แต่พอเอามาใส่รายงาน ฟ้องว่า vn_stat v on v.vn=d.vn ซ้ำกับ vn_stat v1 on v1.vn=d.vn บอกวิธีแก้ให้หน่อยครับ ขอบคุณครับ

 ChangeReportSQL('select v.hospsub,h.name,count(distinct(d.hn) )as p1 ,count(distinct(d.vn)) as p2, '
+'count(distinct(v1.hn)) as a11,count(distinct(v1.vn)) as a12 ,'
+'count(distinct(v2.hn)) as a21,count(distinct(v2.vn)) as a22 ,'
+'count(distinct(v3.hn)) as a31,count(distinct(v3.vn)) as a32 ,'
+'count(distinct(v4.hn)) as a41,count(distinct(v4.vn)) as a42 ,'
+'count(distinct(v5.hn)) as a51,count(distinct(v5.vn)) as a52 ,'
+'count(distinct(v6.hn)) as a61,count(distinct(v6.vn)) as a62 ,'
+'count(distinct(v7.hn)) as a71,count(distinct(v7.vn)) as a72'
+'left outer join vn_stat v on v.vn=d.vn'
+'left outer join vn_stat v1 on v1.vn=d.vn and v1.hn in (select hn from vn_stat where vstdate between "'+d1+'" and "'+d2+'" and age_y between "0" and "2")'
+'left outer join vn_stat v2 on v2.vn=d.vn and v2.hn in (select hn from vn_stat where vstdate between "'+d1+'" and "'+d2+'" and age_y between "0" and "4")'
+'left outer join vn_stat v3 on v3.vn=d.vn and v3.hn in (select hn from vn_stat where vstdate between "'+d1+'" and "'+d2+'" and age_y between "3" and "5")'
+'left outer join vn_stat v4 on v4.vn=d.vn and v4.hn in (select hn from vn_stat where vstdate between "'+d1+'" and "'+d2+'" and age_y between "5" and "6")'
+'left outer join vn_stat v5 on v5.vn=d.vn and v5.hn in (select hn from vn_stat where vstdate between "'+d1+'" and "'+d2+'" and age_y between "6" and "12")'
+'left outer join vn_stat v6 on v6.vn=d.vn and v6.hn in (select hn from vn_stat where vstdate between "'+d1+'" and "'+d2+'" and age_y between "13" and "59")'
+'left outer join vn_stat v7 on v7.vn=d.vn and v7.hn in (select hn from vn_stat where vstdate between "'+d1+'" and "'+d2+'" and age_y between "60" and "200")'
+'left outer join hospcode h on h.hospcode=v.hospsub'
+'where d.vstdate between "'+d1+'" and "'+d2+'" '
+'group by v.hospsub order by v.hospsub desc ');
โรงพยาบาลบ้านเหลื่อม โรงพยาบาลขนาด 30 เตียง
OS : Linux Cenos 5 
Server : hp
Ram : 16 G
นายประพันธ์ศักดิ์ พันศรี (นักวิชาการคอมพิวเตอร์)
E-mail blhospital@hotmail.com

ออฟไลน์ woravet

  • Sr. Member
  • ****
  • กระทู้: 409
  • Respect: +12
    • ดูรายละเอียด
Re: ดู Code ผู้มารับบริการทันตกรรมให้หน่อยครับ
« ตอบกลับ #1 เมื่อ: เมษายน 25, 2013, 12:03:24 PM »
0
ลองแบบนี้มั๊ย
select a.hospsub,ifnull(h.name,'อื่นๆ') name
,count(distinct a.hn) 'case',count(a.hn) 'visit'

,concat(count(distinct if(a.age_y between 0 and 2,a.hn,null)),'/'
,count(if(a.age_y between 0 and 2,a.hn,null))) age_0_2

,concat(count(distinct if(a.age_y between 3 and 5,a.hn,null)),'/'
,count(if(a.age_y between 3 and 5,a.hn,null))) age_3_5

,concat(count(distinct if(a.age_y between 6 and 12,a.hn,null)),'/'
,count(if(a.age_y between 6 and 12,a.hn,null))) age_6_12

,concat(count(distinct if(a.age_y between 13 and 59,a.hn,null)),'/'
,count(if(a.age_y between 13 and 59,a.hn,null))) age_13_59

,concat(count(distinct if(a.age_y>=60,a.hn,null)),'/'
,count(if(a.age_y>=60,a.hn,null))) age_60_more

from (select d.vn,d.hn,v.age_y,v.aid
,if(v.hospsub='' or v.hospsub is null,(select hospitalcode from opdconfig)
,if(v.hospsub in (select hcode from pcu_child),v.hospsub,'99999')) hospsub
from dtmain d
left join vn_stat v on d.vn=v.vn
where d.vstdate between '2013-1-1' and '2013-1-31') a
left join hospcode h on h.hospcode=a.hospsub
group by a.hospsub

รพ.บึงสามัคคี จ.กำแพงเพชร
*********************
อ.สุชัยและคณะ ขึ้นระบบ 29 ตค.49(Linux+Fedara 5)
*********************
ปัจจุบัน
HOSxP version 3.53.4.27
Server:Windows XP SP2,MySQL 5
Client ประมาณ 15 เครื่อง

ออฟไลน์ prapansak

  • Full Member
  • ***
  • กระทู้: 232
  • Respect: 0
    • ดูรายละเอียด
    • http://118.175.76.8/bl/
Re: ดู Code ผู้มารับบริการทันตกรรมให้หน่อยครับ
« ตอบกลับ #2 เมื่อ: เมษายน 25, 2013, 14:44:38 PM »
0
ได้แล้ว ขอบคุณครับ  ;D ;D
โรงพยาบาลบ้านเหลื่อม โรงพยาบาลขนาด 30 เตียง
OS : Linux Cenos 5 
Server : hp
Ram : 16 G
นายประพันธ์ศักดิ์ พันศรี (นักวิชาการคอมพิวเตอร์)
E-mail blhospital@hotmail.com