with at as (
    select *,timestampdiff(second,first_clockin,last_clockin)/3600 as tmp
    from attendent_tb
)
select s.post,round(avg(tmp),3) as work_hours
from at join staff_tb s on at.staff_id=s.staff_id
group by s.post
order by work_hours desc
这题主要是timestampdiff(second,first_clockin,last_clockin)/3600 这一行。
如果单位不是second然后/3600,换算成小时。 而是直接用hour的话, 就会丢失精度, 比如相减是9.5小时,那么只会得到9小时。 离了大谱、

京公网安备 11010502036488号