select
    s.department,
    concat(
        round(
            sum(
                case
                    when timestampdiff(second, first_clockin, last_clockin) / 3600 > 9.5
                    then 1
                    else 0
                end
            ) / count(*) * 100,
            1
        ),
        '%'
    ) as ratio
from
    staff_tb as s
    join attendent_tb as a on s.staff_id = a.staff_id
group by
    s.department
order by
    ratio desc