题解 | 统计各岗位员工平均工作时长
统计各岗位员工平均工作时长
https://www.nowcoder.com/practice/b7220791a95a4cd092801069aefa1cae
select a.post, round(avg(TIMESTAMPDIFF(minute,b.first_clockin , b.last_clockin)/60),3) as work_hours from staff_tb a join attendent_tb b on a.staff_id = b.staff_id where b.first_clockin is not null and b.last_clockin is not null group by a.post order by work_hours desc;
我觉得看到一个取数需求就要按如下这个标准化流程思考(只是个人想法,仅供参考)
1.from 先看来源,你要取哪个表的数,以及是否需要合并表格
2.select 你要输出什么字段
3.where 是否有需要筛选的
4.其他 group by/order by
这个过程中需要注意一些小细节,比如sql最后一个字段后永不加括号
其他语法速成者可当公式记忆

查看5道真题和解析