题解 | 统计各岗位员工平均工作时长
统计各岗位员工平均工作时长
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