BMS-HOSxP Community

HOSxP => Report Exchange => ข้อความที่เริ่มโดย: autobotz ที่ สิงหาคม 20, 2013, 14:30:13 PM

หัวข้อ: รบกวนแนะนำวิธีการแก้ไข SQL ครับ
เริ่มหัวข้อโดย: autobotz ที่ สิงหาคม 20, 2013, 14:30:13 PM
โค๊ด: [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 ช้ามาก ๆ  ผมควรจะปรับแก้ตรงไหนครับ รบกวน ทุก ๆ ท่านช่วยแนะนำทีครับ