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

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

https://www.nowcoder.com/practice/b7220791a95a4cd092801069aefa1cae

# 请统计该公司各岗位员工平均工作时长?

# 注:如员工未打卡该字段数据会存储为NULL,那么不计入在内;

# 要求输出:员工岗位类别Post、平均工作时长work_hours(以小时为单位输出并保留三位小数),按照平均工作时长降序排序;round(,3)

# 先计算出每个员工的工作时长

# 写法一:

# select

# s.post,

# round(avg(a.hours),3) as work_hours

# from staff_tb s

# join (

# select *,

# round((unix_timestamp(last_clockin)-unix_timestamp(first_clockin))/3600,4) as hours

# from attendent_tb

# where first_clockin is not null and last_clockin is not null

# ) a

# on s.staff_id = a.staff_id

# group by s.post

# order by work_hours desc;

# 上面的可以通过,但是为什么用窗口函数就是错的,本地是对的,但在这上边就是无法通过,看到的能帮忙解析一下吗:

# select

# distinct s.post,

# round(avg(a.hours) over(partition by post),3) as work_hours

# from staff_tb s

# join (

# select *,

# round((unix_timestamp(last_clockin)-unix_timestamp(first_clockin))/3600,4) as hours

# from attendent_tb

# where first_clockin is not null and last_clockin is not null

# ) a

# on s.staff_id = a.staff_id

# order by work_hours desc;

# # 写法二:二三都是网友的

# select post, round(avg(timestampdiff(minute,first_clockin,last_clockin))/60,3) as work_hours

# from staff_tb

# join attendent_tb using(staff_id)

# where first_clockin is not null and last_clockin is not null

# group by post

# order by work_hours desc

# 写法三:

with t1 as(

select s.staff_id,

    post,

    -- 注意下这个函数的用法,精确到秒,如果是hour不准确

    TIMESTAMPDIFF(second,first_clockin,last_clockin) / 3600 total_hours

from

    staff_tb s

    join attendent_tb a on s.staff_id = a.staff_id

)

select

post,

round(avg(total_hours),3) work_hours

from t1

group by post

order by work_hours desc

全部评论

相关推荐

吐泡泡的咸鱼:我也工作了几年了,也陆陆续续面试过不少人,就简历来说,第一眼学历不太够,你只能靠你的实习或者论文或者项目经历,然后你没有论文,没有含金量高的比赛和奖项,只能看实习和项目,实习来说,你写的实习经历完全不清楚你想找什么工作?行研?数据分析?且写的太少了,再看项目,这些项目先不说上过大学读过研究生的都知道很水,然后对你想找的岗位有什么帮助呢?项目和实习也完全不匹配啊,你好像在努力将你所有的经历都放在简历里想表现你的优秀,但是对于你想找的岗位来说,有什么用呢?最后只能获得岗位不匹配的评价。所以你需要明白你想要找的岗位要求是什么,是做什么的,比如产品经理,然后再看你的经历里有什么匹配的上这个岗位,或者对这个岗位以及这个岗位所在的公司有价值,再写到你的简历上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务