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

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

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

select post,round(avg(a.hours),3) as work_hours
from(
select staff_tb.staff_id,post,round(timestampdiff(second,first_clockin,last_clockin)/3600,3) as hours #直接用hour的话,会忽略分秒上的差异(因为提示里面举例了单个员工的工作时长,以h为单位,后面有三个小数点,说明员工分秒上面也是有数据的,算时间差时不能忽略)
from attendent_tb
left join staff_tb
on attendent_tb.staff_id=staff_tb.staff_id
having hours is not null) a
group by post
order by work_hours desc

全部评论

相关推荐

机械打工仔:第一位颇有孟德之志
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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