题解 | 统计各岗位员工平均工作时长

统计各岗位员工平均工作时长

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最后一个字段后永不加括号

其他语法速成者可当公式记忆

全部评论

相关推荐

Gardenia06...:刚开始学是这样的,可以看看左神和灵神都讲的不错
点赞 评论 收藏
分享
zaakfung:26届不应该春招吗 为啥还实习
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务