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

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

ออฟไลน์ sshpt

  • Sr. Member
  • ****
  • กระทู้: 446
  • Respect: 0
    • ดูรายละเอียด
    • http://ss-hospital.no-ip.org/
สอบถามการเขียน SQL ให้สั้นลงครับ
« เมื่อ: มิถุนายน 03, 2008, 11:26:10 AM »
0
select an.regdate,an.hn,c.cardno,concat(p.pname," ",p.fname," ",p.lname) as ptname,p.addrpart,p.moopart,t.full_name,an.pdx,p.birthday
from an_stat  an
left outer join patient p on p.hn=an.hn
left outer join ptcardno c on c.hn=an.hn
left outer join thaiaddress t on t.addressid=an.aid
where an.regdate between '2008-05-07' and '2008-05-07'and an.age_y>'64' and an.pdx in ('I05','I06','I07','I08','I09','I11','I13','I20','I21','I22','I23','I24','I25','I26','I27','I28','I29','I30','I31','I32','I33','I34','I35','I36','I37','I38','I39','I40','I41','I42','I43','I44','I45','I46','I47','I48','I49','I50','I51','I52')
group by hn
order by hn

จาก CODE ด้านบน เงื่อนไข  ICD10 ยาวมากครับ
จริง ๆ แล้ว คือ I05-09 และ 11 และ 13 และ 20-52
ถ้าจะเขียนให้สั้นลงกว่านี้ ทำไงครับ   ;D ;D
รพ.เสิงสาง จ.นครราชสีมา  (ขนาด 30 เตียง)  Server IBM eServer xSeries 226 
CPU Xeon 3.0 GHz.  SISC-HD 73 Gb. X 2  ECC-Ram 512 Mb. X 2
ขึ้นระบบโดยทีม BMS เดือน เมษายน 2550
OS CentOS 5.1 MySQL 5.1.23-rc  HosXP V.3.51.9.23 เมื่อ 25 กย. 51
ss-hospital@hotmail.com   >>>   http://ss-hospital.no-ip.org/

ออฟไลน์ pirat

  • Jr. Member
  • **
  • กระทู้: 65
  • Respect: +1
    • ดูรายละเอียด
Re: สอบถามการเขียน SQL ให้สั้นลงครับ
« ตอบกลับ #1 เมื่อ: มิถุนายน 03, 2008, 12:53:20 PM »
0
ใช้แบบนี้ได้ไหมครับ  แต่ข้อมูลที่ได้จะละเอียดขึ้นครับ

select an.regdate,an.hn,c.cardno,concat(p.pname," ",p.fname," ",p.lname) as ptname,p.addrpart,p.moopart,t.full_name,an.pdx,p.birthday
from an_stat  an
left outer join patient p on p.hn=an.hn
left outer join ptcardno c on c.hn=an.hn
left outer join thaiaddress t on t.addressid=an.aid
where an.regdate between '2008-04-01' and '2008-04-30'and an.age_y>'64'
 and an.pdx between "I05" and "I09"
 or pdx between "I11" and "I13"
 or pdx between "I20" and "I52"

group by hn
order by hn
 

ออฟไลน์ sshpt

  • Sr. Member
  • ****
  • กระทู้: 446
  • Respect: 0
    • ดูรายละเอียด
    • http://ss-hospital.no-ip.org/
Re: สอบถามการเขียน SQL ให้สั้นลงครับ
« ตอบกลับ #2 เมื่อ: มิถุนายน 04, 2008, 11:28:35 AM »
0
ขอบคุณครับ ;D
รพ.เสิงสาง จ.นครราชสีมา  (ขนาด 30 เตียง)  Server IBM eServer xSeries 226 
CPU Xeon 3.0 GHz.  SISC-HD 73 Gb. X 2  ECC-Ram 512 Mb. X 2
ขึ้นระบบโดยทีม BMS เดือน เมษายน 2550
OS CentOS 5.1 MySQL 5.1.23-rc  HosXP V.3.51.9.23 เมื่อ 25 กย. 51
ss-hospital@hotmail.com   >>>   http://ss-hospital.no-ip.org/

ออฟไลน์ manoi

  • Hero Member
  • *****
  • กระทู้: 8,669
  • Respect: +170
    • ดูรายละเอียด
    • HOSxP Community Center
Re: สอบถามการเขียน SQL ให้สั้นลงครับ
« ตอบกลับ #3 เมื่อ: มิถุนายน 04, 2008, 11:42:29 AM »
0
ใช้แบบนี้ได้ไหมครับ  แต่ข้อมูลที่ได้จะละเอียดขึ้นครับ

select an.regdate,an.hn,c.cardno,concat(p.pname," ",p.fname," ",p.lname) as ptname,p.addrpart,p.moopart,t.full_name,an.pdx,p.birthday
from an_stat  an
left outer join patient p on p.hn=an.hn
left outer join ptcardno c on c.hn=an.hn
left outer join thaiaddress t on t.addressid=an.aid
where an.regdate between '2008-04-01' and '2008-04-30'and an.age_y>'64'
 and   an.pdx between "I05" and "I09"
 or pdx between "I11" and "I13"
 or pdx between "I20" and "I52" 

group by hn
order by hn


จริงๆ ต้องเป็นแบบนี้ครับ

select an.regdate,an.hn,c.cardno,concat(p.pname," ",p.fname," ",p.lname) as ptname,p.addrpart,p.moopart,t.full_name,an.pdx,p.birthday
from an_stat  an
left outer join patient p on p.hn=an.hn
left outer join ptcardno c on c.hn=an.hn
left outer join thaiaddress t on t.addressid=an.aid
where an.regdate between '2008-04-01' and '2008-04-30'and an.age_y>'64'
 and ( an.pdx between "I05" and "I0999999"
 or pdx between "I11" and "I1399999"
 or pdx between "I20" and "I5299999" )

group by hn
order by hn
HOSxP Project Manager / Cheif Developer / BMS MD