题解 | 统计各岗位员工平均工作时长
统计各岗位员工平均工作时长
https://www.nowcoder.com/practice/b7220791a95a4cd092801069aefa1cae
select a.post,round(avg((UNIX_TIMESTAMP(last_clockin) - UNIX_TIMESTAMP(first_clockin)) / 3600),3) work_hours from staff_tb a join attendent_tb b using(staff_id) where b.first_clockin is not null and b.last_clockin is not null group by a.post order by work_hours desc
UNIX_TIMESTAMP(last_clockin) - UNIX_TIMESTAMP(first_clockin)) / 3600 计算精确到秒的日期差,/3600为小时差 /60 为分钟差
