题解 | 统计各岗位员工平均工作时长
统计各岗位员工平均工作时长
https://www.nowcoder.com/practice/b7220791a95a4cd092801069aefa1cae
select
post,avg(round(TIMESTAMPDIFF(MINUTE,first_clockin,last_clockin)/60,3)) as work_hours
from
staff_tb
natural join attendent_tb
group by
post
order by
work_hours desc
sql执行顺序,from➡️where➡️group by➡️having➡️select➡️distinct➡️order by➡️limit/offset
思路:自然连接两个表,根据post分组,然后select得到每组的平均工作时间(TIMESTAMPDIFF函数,不能用timediff,它会把时间直接变成数字,不做转换)
查看7道真题和解析
