ผู้เขียน หัวข้อ: สอบถามคำสัง SQL ครับ  (อ่าน 3529 ครั้ง)

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

ออฟไลน์ panus_t

  • Hero Member
  • *****
  • กระทู้: 2,368
  • Respect: +8
    • ดูรายละเอียด
สอบถามคำสัง SQL ครับ
« เมื่อ: กรกฎาคม 12, 2011, 11:44:24 AM »
0
สอบถามคำสัง SQL ครับ
จากตัวรายงาน ต้องการ ตัดช่อง Lab และ ยา ออก แต่ให้นำคำสั่งดึง Lab และ ยา ไปรวมกับ SQL หลักได้อย่างไรครับ
ความต้องการคือ
1.ช่อง Lab และ ยา ไม่ต้องแสดงใน paper และ แต่จะให้แสดง ตอนส่งรายงานออกเป็น Excel แทน
2.ในไฟล์ Excel แสดงรายชื่อไม่ซ้ำกันด้วยครับ
โรงพยาบาลเสิงสาง จ.นครราชสีมา (ขนาด  60  เตียง ปี2554)  ขึ้นระบบโดยทีมงาน BMS  เมื่อเดือนเมษายน 2551
ก่อนหน้านั้นขึ้นระบบเมื่อ 07/07/07 ฤกษ์ดี  Master Server  IBM System x3500M4  RAM ECC 24 GB. HardDisk SAS 450x3 GB. ServerRAID M1100 Series Zero RAID5  OS:CentOS 6.4  MySQLPercona : 5.5.30-30.1

ออฟไลน์ panus_t

  • Hero Member
  • *****
  • กระทู้: 2,368
  • Respect: +8
    • ดูรายละเอียด
Re: สอบถามคำสัง SQL ครับ
« ตอบกลับ #1 เมื่อ: กรกฎาคม 12, 2011, 15:29:10 PM »
0
select ov.vn,ov.vstdate,pt.hn,concat (pt.pname,' ',pt.fname,'  ',pt.lname) as ptname,ov.age_y,os.bw,os.height,os.bmi,
os.fbs,os.bps,os.bpd,pt.addrpart,pt.moopart,ta.full_name,concat (ov.pdx) as pdx,concat (ov.dx0) as dx0,
concat (ov.dx1) as dx1,concat (ov.dx2) as dx2,concat (ov.dx3) as dx3,concat (ov.dx4) as dx4,concat (ov.dx5) as dx5 ,
lh.lab_order_number
from vn_stat ov
left outer join patient pt on pt.hn=ov.hn
left outer join ovst ovst on ov.vn=ovst.vn
left outer join thaiaddress ta on ov.aid=ta.addressid
left outer join icd101 icd on icd.code=ov.pdx
left outer join opdscreen os on os.vn=ov.vn
left outer join lab_head lh on lh.vn=ov.vn
where ov.vstdate between "2011-05-01" and  "2011-05-31"
and ov.aid<>"300301"
and ( (ov.pdx >= "E100" and ov.pdx <= "E119")
or (ov.dx0 >= "E100" and ov.dx0 <= "E119")
or (ov.dx1 >= "E100" and ov.dx1 <= "E119")
or (ov.dx2 >= "E100" and ov.dx2 <= "E119")
or (ov.dx3 >= "E100" and ov.dx3 <= "E119")
or (ov.dx4 >= "E100" and ov.dx4 <= "E119")
or (ov.dx5 >= "E100" and ov.dx5 <= "E119") )
order by pt.tmbpart , pt.moopart , pt.addrpart

จากโค้ดด้านบน ผมต้องการดึง Lab มาต่อท้ายโดยมีโค้ดังนี้

select concat(li.lab_items_name," = ",lo.lab_order_result) as
lab_result  from lab_head lh
left outer join lab_order lo on lo.lab_order_number=lh.lab_order_number
left outer join lab_items li on li.lab_items_code=lo.lab_items_code
where lh.vn="'+dbpipeline['vn']+'"  and lo.lab_items_code in ("78","92","193","400")


ต้องทำไปแทรกโค้ดอันแรกได้หรือเปล่าครับ
โรงพยาบาลเสิงสาง จ.นครราชสีมา (ขนาด  60  เตียง ปี2554)  ขึ้นระบบโดยทีมงาน BMS  เมื่อเดือนเมษายน 2551
ก่อนหน้านั้นขึ้นระบบเมื่อ 07/07/07 ฤกษ์ดี  Master Server  IBM System x3500M4  RAM ECC 24 GB. HardDisk SAS 450x3 GB. ServerRAID M1100 Series Zero RAID5  OS:CentOS 6.4  MySQLPercona : 5.5.30-30.1

ออฟไลน์ lo_singburihosp

  • Newbie
  • *
  • กระทู้: 31
  • Respect: 0
    • ดูรายละเอียด
    • http://www.singburihosp.go.th
Re: สอบถามคำสัง SQL ครับ
« ตอบกลับ #2 เมื่อ: กรกฎาคม 12, 2011, 17:51:59 PM »
0
select ov.vn,ov.vstdate,pt.hn,concat (pt.pname,' ',pt.fname,'  ',pt.lname) as ptname,ov.age_y,os.bw,os.height,os.bmi,
os.fbs,os.bps,os.bpd,pt.addrpart,pt.moopart,ta.full_name,concat (ov.pdx) as pdx,concat (ov.dx0) as dx0,
concat (ov.dx1) as dx1,concat (ov.dx2) as dx2,concat (ov.dx3) as dx3,concat (ov.dx4) as dx4,concat (ov.dx5) as dx5 ,
lh.lab_order_number,
l1.lab_order_result,l2.lab_order_result,l3.lab_order_result,l4.lab_order_resultfrom vn_stat ov
left outer join patient pt on pt.hn=ov.hn
left outer join ovst ovst on ov.vn=ovst.vn
left outer join thaiaddress ta on ov.aid=ta.addressid
left outer join icd101 icd on icd.code=ov.pdx
left outer join opdscreen os on os.vn=ov.vn
left outer join lab_head lh on lh.vn=ov.vn
left outer join lab_order l1 on l1.lab_order_number = lh.lab_order_number and l1.lab_items_code = '78'
left outer join lab_order l2 on l2.lab_order_number = lh.lab_order_number and l1.lab_items_code = '92'
left outer join lab_order l3 on l3.lab_order_number = lh.lab_order_number and l1.lab_items_code = '193'
left outer join lab_order l4 on l4.lab_order_number = lh.lab_order_number and l1.lab_items_code = '400'
where ov.vstdate between "2011-05-01" and  "2011-05-31"
and ov.aid<>"300301"
and ( (ov.pdx >= "E100" and ov.pdx <= "E119")
or (ov.dx0 >= "E100" and ov.dx0 <= "E119")
or (ov.dx1 >= "E100" and ov.dx1 <= "E119")
or (ov.dx2 >= "E100" and ov.dx2 <= "E119")
or (ov.dx3 >= "E100" and ov.dx3 <= "E119")
or (ov.dx4 >= "E100" and ov.dx4 <= "E119")
or (ov.dx5 >= "E100" and ov.dx5 <= "E119") )
order by pt.tmbpart , pt.moopart , pt.addrpart


ลองดูนะครับ
admin รพ.สิงห์บุรี ขนาด 310 เตียง
hosxp ver 3.55.2.10
hosxp Blood Bank
sever IBM Power PPC 2.4 Gb. Ram 4 Gb.
linux Redhat Enterprise Power PPC

ออฟไลน์ panus_t

  • Hero Member
  • *****
  • กระทู้: 2,368
  • Respect: +8
    • ดูรายละเอียด
Re: สอบถามคำสัง SQL ครับ
« ตอบกลับ #3 เมื่อ: กรกฎาคม 13, 2011, 10:39:02 AM »
0
ขอบคุณครับ ... ผมต้องการดึงยาอีก แต่ทำไม่ได้ครับ จำนวนเรคคอร์ดมันเพิ่มขึ้น (ขื่อผู้ป่วยซ้ำ) เลยขอความช่วยเหลือดูโค้ดให้อีกทีครับ

select ov.vn,ov.vstdate,pt.hn,concat (pt.pname,' ',pt.fname,'  ',pt.lname) as ptname,ov.age_y,os.bw,os.height,os.bmi,
os.fbs,os.bps,os.bpd,pt.addrpart,pt.moopart,ta.full_name,concat (ov.pdx) as pdx,concat (ov.dx0) as dx0,
concat (ov.dx1) as dx1,concat (ov.dx2) as dx2,concat (ov.dx3) as dx3,concat (ov.dx4) as dx4,concat (ov.dx5) as dx5 ,
lh.lab_order_number,li.lab_items_name,lo.lab_order_result as Creatinine,lo92.lab_order_result as LDL,
lo193.lab_order_result as HbA1C,lo400.lab_order_result as UrineMicroalbumin,concat (di.name," - ",di.strength) as drug_namefrom vn_stat ov
left outer join patient pt on pt.hn=ov.hn
left outer join ovst ovst on ov.vn=ovst.vn
left outer join thaiaddress ta on ov.aid=ta.addressid
left outer join icd101 icd on icd.code=ov.pdx
left outer join opdscreen os on os.vn=ov.vn
left outer join lab_head lh on lh.vn=ov.vn
left outer join lab_order lo on lo.lab_order_number=lh.lab_order_number and lo.lab_items_code="78"
left outer join lab_order lo92 on lo92.lab_order_number=lh.lab_order_number and lo92.lab_items_code="92"
left outer join lab_order lo193 on lo193.lab_order_number=lh.lab_order_number and lo193.lab_items_code="193"
left outer join lab_order lo400 on lo400.lab_order_number=lh.lab_order_number and lo400.lab_items_code="400"
left outer join lab_items li on li.lab_items_code=lo.lab_items_code
left outer join opitemrece ot on ot.vn=ov.vn
left outer join drugitems di on di.icode=ot.icode and di.icode="1000039"

where ov.vstdate between "2011-05-01" and  "2011-05-31"
and ov.aid<>"300301"
and ( (ov.pdx >= "E100" and ov.pdx <= "E119")
or (ov.dx0 >= "E100" and ov.dx0 <= "E119")
or (ov.dx1 >= "E100" and ov.dx1 <= "E119")
or (ov.dx2 >= "E100" and ov.dx2 <= "E119")
or (ov.dx3 >= "E100" and ov.dx3 <= "E119")
or (ov.dx4 >= "E100" and ov.dx4 <= "E119")
or (ov.dx5 >= "E100" and ov.dx5 <= "E119") )
order by pt.tmbpart , pt.moopart , pt.addrpart

เพิ่มยาอีกหลายตัวครับ
icode
1000038
1000122
1500801
1530045
1000278
1460090
โรงพยาบาลเสิงสาง จ.นครราชสีมา (ขนาด  60  เตียง ปี2554)  ขึ้นระบบโดยทีมงาน BMS  เมื่อเดือนเมษายน 2551
ก่อนหน้านั้นขึ้นระบบเมื่อ 07/07/07 ฤกษ์ดี  Master Server  IBM System x3500M4  RAM ECC 24 GB. HardDisk SAS 450x3 GB. ServerRAID M1100 Series Zero RAID5  OS:CentOS 6.4  MySQLPercona : 5.5.30-30.1