ผู้เขียน หัวข้อ: รบกวนแนะนำวิธีการแก้ไข SQL ครับ  (อ่าน 2703 ครั้ง)

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

ออฟไลน์ autobotz

  • Jr. Member
  • **
  • กระทู้: 85
  • Respect: 0
    • ดูรายละเอียด
รบกวนแนะนำวิธีการแก้ไข SQL ครับ
« เมื่อ: สิงหาคม 20, 2013, 14:30:13 PM »
0
โค๊ด: [Select]
select * from
(
select v.hn,concat(p.pname,p.fname,space(3),p.lname) as ptname,

(select o.bps from opdscreen o
where o.hn = v.hn
and o.vstdate between @d1 and @d2
order by o.vstdate desc limit 0,1) as bps,

(select o.bpd from opdscreen o
where o.hn = v.hn
and o.vstdate between @d1 and @d2
order by o.vstdate desc limit 0,1) as bpd,



(select o1.bps from opdscreen o1
where o1.hn = v.hn
order by o1.vstdate desc limit 1,1) as bps1,

(select o1.bpd from opdscreen o1
where o1.hn = v.hn
order by o1.vstdate desc limit 1,1) as bpd1,



(select o2.bps from opdscreen o2
where o2.hn = v.hn
order by o2.vstdate desc limit 2,1) as bps2,
(select o1.bpd from opdscreen o1
where o1.hn = v.hn
order by o1.vstdate desc limit 2,1) as bpd2





from vn_stat v
left join patient p on p.hn = v.hn
where v.vstdate between @d1 and @d2
and (v.pdx in ('i10')
or v.dx0 in ('i10')
or v.dx1 in ('i10')
or v.dx2 in ('i10')
or v.dx3 in ('i10')
or v.dx4 in ('i10')
or v.dx5 in ('i10')
)
group by v.hn
order by v.aid desc ,p.pname,p.fname,p.lname
)
as cctemp
where bps <= 140 and bpd<= 90
and bps1 <= 140 and bpd1 <= 90
and bps2 <= 140 and bpd2 <= 90



จาก SQL ข้างบน  จะ Query ช้ามาก ๆ  ผมควรจะปรับแก้ตรงไหนครับ รบกวน ทุก ๆ ท่านช่วยแนะนำทีครับ
นายทัศนัย  อ้ายพุก
เจ้าหน้าที่คอมพิวเตอร์ชั้น 4
โรงพยาบาลค่ายพิชัยดาบหัก

40 Client
Main Server : HP
CPU : Intel Xeon X3450 2.67GHz 8 cores 64 bit
RAM : 16 Gb
OS : CentOs 6.5
DB : MySQL Percona 5.5.33-31.1

Secondary Server HP
CPU : Intel Xeon X3450 2.67GHz 8 cores 64 bit
RAM : 4 Gb
OS : CentOs 6.5
DB : MySQL Percona 5.5.33-31.1


Client version 3.56.11.19
Structure  3.56.11.19