题解 | 统计加班员工占比

统计加班员工占比

https://www.nowcoder.com/practice/6c0a521c36e14c7599eaef858f6f8233

# 考察左连接的使用
select department,concat(round(count(a.staff_id)/count(s.staff_id)*100,1),'%') ratio
from staff_tb s left join attendent_tb a 
on a.staff_id = s.staff_id
and timestampdiff(minute,first_clockin,last_clockin) > 570
group by department
order by ratio desc
# 以部门员工信息表为主表
# 左连接出勤表,链接条件是出勤时长超过9.5小时,那么未加班的员工id就变成了null
# 右表加班的员工数/员工全表的id数为加班比率
# 员工信息为全表则即使没有加班的也会被显示出来

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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