题解 | 统计各岗位员工平均工作时长
统计各岗位员工平均工作时长
https://www.nowcoder.com/practice/b7220791a95a4cd092801069aefa1cae
SELECT post, ROUND((SUM(w_hour) / COUNT(w_hour)) , 3) AS work_hours FROM staff_tb AS s LEFT JOIN (SELECT staff_id, TIMESTAMPDIFF(minute,first_clockin,last_clockin)/60 AS w_hour FROM attendent_tb) AS b ON s.staff_id = b.staff_id GROUP BY post ORDER BY work_hours DESC #难点:有部分员工未打卡,计算员工数时需注意COUNT(w_hour)