题解 | #统计各岗位员工平均工作时长#
统计各岗位员工平均工作时长
https://www.nowcoder.com/practice/b7220791a95a4cd092801069aefa1cae
SELECT post, ROUND(AVG(work_hours), 3) AS work_hours FROM (SELECT staff_id, TIME_TO_SEC(TIMEDIFF(last_clockin, first_clockin)) / 3600 AS work_hours FROM attendent_tb) t LEFT JOIN staff_tb s ON s.staff_id = t.staff_id GROUP BY post ORDER BY work_hours DESC;