题解 | 统计各岗位员工平均工作时长
统计各岗位员工平均工作时长
https://www.nowcoder.com/practice/b7220791a95a4cd092801069aefa1cae
with group1 as (
select
post,
round(avg(timestampdiff(second,first_clockin,last_clockin) / 3600),3) as work_hours
#应用hour的话不准确
from staff_tb s1
left join attendent_tb a1 on s1.staff_id = a1.staff_id
where first_clockin is not null and last_clockin is not null
group by post
)
select
post,
work_hours
from group1
order by work_hours desc