SELECT department,CONCAT(ROUND(SUM(IF(TIMESTAMPDIFF(MINUTE,first_clockin,last_clockin)/60 > 9.5, 1, 0))/COUNT(staff_name)*100,1),'%') AS ratio FROM staff_tb LEFT JOIN attendent_tb USING(staff_id) GROUP BY department ORDER BY ratio DESC