select department,concat(round(avg(if(TIMESTAMPDIFF(MINUTE,first_clockin,last_clockin)/60>9.5,1,0))*100,1),'%') as ratio from attendent_tb a left join staff_tb b on a.staff_id = b.staff_id group by department order by ratio desc