题解 | #统计各岗位员工平均工作时长#

统计各岗位员工平均工作时长

https://www.nowcoder.com/practice/b7220791a95a4cd092801069aefa1cae

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

全部评论

相关推荐

2025-12-27 22:46
门头沟学院 Java
点赞 评论 收藏
分享
StephenZ_:我9月份找的第一段实习也是遇到这种骗子公司了,问他后端有多少人和我说7个正职,进去一看只有一个后端剩下的都是产品前端算法(没错甚至还有算法)。还是某制造业中大厂,我离职的时候还阴阳怪气我
点赞 评论 收藏
分享
2025-12-09 16:37
西北大学 前端工程师
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务