select 
    post,
    -- 计算平均工作时间,从分钟转换为小时,结果保留三位小数
    round(avg(timestampdiff(minute, first_clockin, last_clockin)) / 60, 3) as work_hours
from 
    attendent_tb a
    -- 连接员工表和考勤表,使用 staff_id 进行连接
    join staff_tb s on a.staff_id = s.staff_id
-- 过滤掉没有打卡记录的记录
where first_clockin is not null and last_clockin is not null
-- 按职位分组,计算每个职位的平均工作时间
group by post
-- 按工作时间降序排列结果
order by work_hours desc