ลองคำสั่งนี้ดู
select o.vn,o.hn,c.number,concat(p.pname,p.fname," ",p.lname) as ptname
,o.vstdate,o.vsttime,s.bw,s.height,s.bmi,s.bps,s.bpd
,if(s.bps between 140 and 159 or s.bpd between 90 and 99,'1'
,if(s.bps between 160 and 179 or s.bpd between 100 and 109,'2'
,if(s.bps>=180 or s.bpd>=110,'3'
,if(s.bps is null or s.bpd is null,'Error',' ')))) 'BP_Grade'
,if(s.bps between 140 and 159 or s.bpd between 90 and 99,1,0) 'BP_Grade1'
,if(s.bps between 160 and 179 or s.bpd between 100 and 109,1,0) 'BP_Grade2'
,if(s.bps>=180 or s.bpd>=110,1,0) 'BP_Grade3'
,s.tg,s.ldl,s.hdl,s.hbA1c,s.creatinine,s.ua
,s.fbs
,if(s.fbs is null,'Error'
,if(s.fbs<=125,'Normal',if(s.fbs<=154,'1',if(s.fbs<=182,'2','3')))) 'FBS_Grade'
,if(s.fbs between 126 and 154,1,0) 'FBS_Grade1'
,if(s.fbs between 155 and 182,1,0) 'FBS_Grade2'
,if(s.fbs>=183,1,0) 'FBS_Grade3'
from ovst o
left join patient p on p.hn=o.hn
left join opdscreen s on o.vn=s.vn
left join clinicmember c on c.hn=o.hn
where o.vstdate between '2012-01-01' and '2012-06-30'
and c.clinic ="001"
order by o.hn,o.vn