select 
sb.department,
concat(
round(
(
count(distinct case when timestampdiff(second,first_clockin,last_clockin)/3600>9.5  then sb.staff_id end)/count(distinct sb.staff_id))*100,1),"%") as ratio

from staff_tb sb inner join attendent_tb ab 
on sb.staff_id=ab.staff_id
group by sb.department
order by ratio desc