select department,concat(round(sum(if(timestampdiff(minute,first_clockin,last_clockin)/60>9.5,1,0))/count(*)*100,1),'%') ratio from staff_tb s join attendent_tb a on s.staff_id=a.staff_id group by department order by ratio desc