select v.hn as hn,l.lab_count,xh.confirm_all,l.report_count,v.pt_priority as pt_priority,v.vn as vn,v.oqueue as oqueue,v.cur_dep_time as cur_dep_time,count(s.vn) as svn_count, count(r.vn) as rx_count,count(r1.vn) as pay_count , count(t.vn) as finance_count , concat(p.pname,p.fname,' ',p.lname) as ptname from ovst v left outer join patient p on p.hn=v.hn left outer join pq_screen s on s.vn=v.vn left outer join rx_operator r on r.vn=v.vn left outer join rcpt_print t on t.vn=v.vn left outer join lab_status l on l.vn = v.vn left outer join xray_head xh on xh.vn = v.vn left outer join rx_operator r1 on r1.vn=v.vn and r1.pay='Y' where v.vstdate='2008-11-22' and v.hn='000262291' group by v.hn,l.lab_count,xh.confirm_all,l.report_count,v.pt_priority,v.vn,v.oqueue,v.cur_dep_time,p.pname,p.fname,p.lname order by v.pt_priority desc, v.cur_dep_time
v.pt_priority