将时间聚合数据分解为几个均匀分布的间隔
数据库结构如下所示。 它只是代表员工、正在处理的任务数量、开始整个活动的事实以及结束的事实和所花费的秒数的总摘要的一行。
员工 | number_of_tasks | start_act | end_act | total_seconds |
---|---|---|---|---|
AXF-6263 | 5 | 12:30 | 14:10 | 6000 |
我想将其按相等的时间间隔分解,每次 1 小时,另外总结总秒数,落入特定的时间间隔。从而得到这样的结果。那么有没有什么SQL方法可以解决这个问题呢?
员工 | number_of_tasks | start_act | end_act | Total_seconds |
---|---|---|---|---|
AXF-6263 | 5 | 12:00 | 13:00 | 1800 |
AXF-6263 | 5 | 13:00 | 14:00 | 3600 |
AXF-6263 | 5 | 14:00 | 15:00 | 600 |
提前感谢您提供任何帮助!
The database structure looks like this.
It's just a single row representing employee, number of tasks were being processed, the fact of starting whole activity and also the fact of ending and total summary of spent seconds.
employee | number_of_tasks | start_act | end_act | total_seconds |
---|---|---|---|---|
AXF-6263 | 5 | 12:30 | 14:10 | 6000 |
I want to break this down on equal intervals for 1 hour each, additionally summing up total seconds, falling into particular interval. Thus getting a reslut like this. So is there any kind of SQL approach to implement this problem ?
employee | number_of_tasks | start_act | end_act | total_seconds |
---|---|---|---|---|
AXF-6263 | 5 | 12:00 | 13:00 | 1800 |
AXF-6263 | 5 | 13:00 | 14:00 | 3600 |
AXF-6263 | 5 | 14:00 | 15:00 | 600 |
Thanks in advance for any kind of help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的任务,我决定加入一个系列,然后找出他的重叠部分。
我的方法是采用灵活的时间单位,这样您就可以更改为天/周/等
Interesting task, I decided to join on a series then figure out he overlap.
My approach here, with a flexible time unit so you could change to days/weeks/etc
使用
generate_series
并将其与您的表交叉连接。Use
generate_series
and cross join it with your table.