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

select post,
round(avg(timestampdiff(second,first_clockin,last_clockin)/3600),3) as work_hours
from staff_tb
join attendent_tb
using(staff_id)
where first_clockin is not null
group by post
order by work_hours desc

知识点:timestampdiff()函数的使用

易错点:1)不能对timestampdiff直接用hour,用second/minute换算小时重新计算工作时长。注意timestampdiff()函数会直接截断小数部分,而不是四舍五入

全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 17:10
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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