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