gpt4 book ai didi

sql - 查找配置单元中每个ID的平均小时数

转载 作者:行者123 更新时间:2023-12-02 22:06:29 24 4
gpt4 key购买 nike

我的数据集看起来像这样:-

 Id      working_hour
1005 2019-10-23 08:35:00
1006 2019-10-23 00:54:59
1007 2019-10-23 00:24:57
1008 2019-10-23 06:40:00
1009 2019-10-23 03:50:00
1010 2019-10-23 03:25:01
1005 2019-10-24 05:25:00
1006 2019-10-24 01:39:59
1007 2019-10-24 02:30:00
1008 2019-10-24 09:45:01
1010 2019-10-24 07:00:00

这是两天的数据集(23/10/2019和24/10/2019)。我想让Ro查找每个ID的平均工作时间(以小时或分钟为单位)。

喜欢:-
 Id    in_hours  in_mins
1005 7 420 # (08:35+3:35)/2 = 7 hours
1006 1.29 77.4835 # (00:54:59+01:39:59)/2 = 1.29 hours

最佳答案

我正在尽可能简单地使用它。对我来说,它工作正常。

SELECT user_name, from_unixtime(CAST(AVG(unix_timestamp(substr(working_hours,12),"HH:mm:ss"))as bigint),"HH:mm:ss") as avg_hours FROM workinglogs1 GROUP BY user_name ORDER BY avg_hours'

在这里,我仅使用substr(working_hours,12)从工作时间开始仅对HH:mm:ss进行测试,然后找到工作时间的unix_time时间戳。之后,我要进行平均,并使用from_unixtime转换为时间戳。

关于sql - 查找配置单元中每个ID的平均小时数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61856158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com