SELECT department, CONCAT( ROUND(COUNT(IF(TIMESTAMPDIFF(MINUTE, first_clockin, last_clockin) > 9.5*60, 1, NULL)) / COUNT(*) * 100,1), '%' ) AS ratio FROM attendent_tb a JOIN staff_tb s ON a.staff_id = s.staff_id GROUP BY department ORDER BY ratio DESC;