select
department,
concat (round(100 * avg(is_time), 1), '%') as ratio
from
(
select
staff_id,
if (
timestampdiff (second, first_clockin, last_clockin) / 3600 > 9.5,
1,
0
) as is_time
from
attendent_tb
) as t1
join staff_tb s on s.staff_id = t1.staff_id
group by
department
order by
ratio desc

京公网安备 11010502036488号