2
« เมื่อ: พฤษภาคม 02, 2014, 09:39:22 AM »
รายชื่อผู้ป่วย HT ที่มี BP น้อยกว่า 140/90 จำนวน 2 ครั้งติดกัน เลือกในช่วงที่ที่ต้องการได้
select *
from(select v.hn,concat(p.pname,p.fname,space(3),p.lname) as ptname,p.clinic,sc.bps,sc.bpd,
(select sc.bps
from opdscreen sc1
where sc1.vstdate between DATE_ADD("2014-01-01", INTERVAL -1 MONTH) and DATE_ADD("2014-04-20", INTERVAL -1 MONTH)
and sc1.hn = v.hn
) as bps1,
(select sc.bps from opdscreen sc2
where sc2.vstdate between DATE_ADD("2014-01-01", INTERVAL -2 MONTH) and DATE_ADD("2014-04-20", INTERVAL -2 MONTH)
and sc2.hn = v.hn
) as bps2,
(select sc.bpd
from opdscreen sc3
where sc3.vstdate between DATE_ADD("2014-01-01", INTERVAL -1 MONTH) and DATE_ADD("2014-04-20", INTERVAL -1 MONTH)
and sc3.hn = v.hn
) as bpd1,
(select sc.bpd
from opdscreen sc4
where sc4.vstdate between DATE_ADD("2014-01-01", INTERVAL -2 MONTH) and DATE_ADD("2014-04-20", INTERVAL -2 MONTH)
and sc4.hn = v.hn
) as bpd2
from vn_stat v
left join opdscreen sc on sc.vn = v.vn
left join patient p on p.hn = v.hn
where v.vstdate between "2014-01-01" and "2014-04-20"
and p.clinic like '%àºÒËÇÒ¹%' (?ตรงนี้คืออะไร)
and sc.bps is not null
and (sc.bps<= "140" and sc.bpd<= "90")
and v.vstdate between "2014-01-01" and "2014-04-20"
group by v.hn
order by v.aid desc ,v.vstdate,v.hn) as ttemp
where bps<= "140" and bps1<= "140" and bps2<= "140"