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

京公网安备 11010502036488号