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

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

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-17 17:53
门头沟学院 Web前端
海梨花:我之前面试也是问我非技术问题,问过我怎么统计北京出租车数量,不借助任何网络或者其他平台的帮助,有足够多的人可以帮忙
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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