题解 | 统计各岗位员工平均工作时长
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()函数会直接截断小数部分,而不是四舍五入