大厂真题SQL 10 题解 | 统计各岗位员工平均工作时长

# 需求分析
#注:如员工未打卡该字段数据会存储为NULL,那么不计入在内。
# 保留三位小数
# 平均时间排序,where ,排序,group by

# 分钟计算为小时,打卡 TIMESTAMPDIFF,MINUTE不能加引号
# timstampdiff 先小后大,和datediff不一样


SELECT a.post,ROUND(AVG(TIMESTAMPDIFF(minute,first_clockin,last_clockin)/60),3) as work_hours
FROM staff_tb a
left join attendent_tb b
on a.staff_id=b.staff_id
where TIMESTAMPDIFF(minute,first_clockin,last_clockin)>0
group by a.post
order by ROUND(AVG(TIMESTAMPDIFF(minute,first_clockin,last_clockin)/60),3)   desc

全部评论

相关推荐

04-13 11:19
门头沟学院 HTML5
NullPointe...:27实习的都快结束了吧
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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