select s.department, concat(round(avg(if(timestampdiff(minute, a.first_clockin, a.last_clockin)/60 > 9.5, 1, 0))*100, 1), "%") as ratio
from staff_tb s
join attendent_tb a using(staff_id)
group by s.department
order by ratio desc