select a.vstdate,a.vn,a.hn,concat(pname,fname," ",lname) as ptname,
a.vsttime as begintime,
a.service4 as screen,
sec_to_time(time_to_sec(a.service4)-time_to_sec(a.vsttime)) as watingtimescreen,
a.service11 as screentime,
sec_to_time(time_to_sec(a.service11)-time_to_sec(a.service4)) as timescreen,
a.service5 as doctortime,
sec_to_time(time_to_sec(a.service5)-time_to_sec(a.service11)) as waitingdoctortime,
a.service12 as doctorendtime,
sec_to_time(time_to_sec(a.service12)-time_to_sec(a.service5)) as doctorwatingtime,
a.service6 as jadya,
sec_to_time(time_to_sec(a.service6)-time_to_sec(a.service12)) as jadyawatingtime,
sec_to_time(time_to_sec(a.service6)-time_to_sec(a.vsttime)) as watingtime
from service_time a
left outer join patient b on a.hn=b.hn
left outer join ovst o on o.vn=a.vn
where a.vstdate between'2010-07-01'and'2010-07-01'
and o.visit_type="I"
จากคำสั่งข้างต้นฝากช่วยแก้ โดยเพิ่มเงื่อนไข ไม่รวมผู้ป่วยที่สั่ง LAB