มันไม่ค่อย ตรงกับที่จะใ้ช้ อ่ะครับ
อย่างนี้ตรงไหมครับ
select temp.vstdate,
case
when time_to_sec(temp.wait_time)<300 then "01|<5min"
when time_to_sec(temp.wait_time)<601 then "02|5-10min"
when time_to_sec(temp.wait_time)<1201 then "03|>10-20min"
when time_to_sec(temp.wait_time)<1801 then "04|>20-30min"
when time_to_sec(temp.wait_time)<2401 then "05|>30-40min"
when time_to_sec(temp.wait_time)<3001 then "06|>40-50min"
when time_to_sec(temp.wait_time)<3601 then "07|>50-60min"
when time_to_sec(temp.wait_time)<7201 then "08|>1-2hr"
when time_to_sec(temp.wait_time)<10801 then "09|>2-3hr"
else "10|>3hr"
end as wait_range, count(vn)
from
(select o.vstdate, o.vn, o.hn, o.oqueue, concat(p.pname,p.fname,' ',p.lname) as ptname, o.vsttime, t.service11, t.service12, t.service6, t.service19, r.rx_time, t.service16,
if(t.service12 is not null,sec_to_time(time_to_sec(r.rx_time)-time_to_sec(t.service12)),if(t.service19 is not null,sec_to_time(time_to_sec(r.rx_time)-time_to_sec(t.service19)),sec_to_time(time_to_sec(r.rx_time)-time_to_sec(t.service11)))) as wait_time
from rx_operator r
left outer join ovst o on o.vn=r.vn
left outer join patient p on p.hn=o.hn
left outer join service_time t on t.vn=r.vn
where o.vstdate between "2010-09-01" and "2010-09-14" and r.pay='Y' and r.pay_depcode="036"
order by r.rx_time) as temp
group by temp.vstdate, wait_range
http://hosxp.net/index.php?option=com_smf&Itemid=28&topic=17347.msg140821#new