问题描述
T-SQL、SQL Server 2008 及更高版本
T-SQL, SQL Server 2008 and up
给定一个样本表
我需要将其分解为使用 15 分钟间隔的视图,例如:
I need to break that down into a view that uses 15 minute intervals for example:
现在我已经能够四处搜索并找到一些会崩溃的查询我在这里找到了类似的东西:
Now I've been able to search around and find some queries that will break down I found something similar for MySql Here :
T-SQL 的一些东西这里
And something for T-SQL Here
但在第二个示例中,他们对结果求和,而我需要将总持续时间除以用户按状态的间隔时间(900 秒).
But on the second example they are summing the results whereas I need to divide the total duration by the interval time (900 seconds) by user by status.
我能够调整第二个链接中的示例以将所有内容拆分为间隔,但返回了总持续时间,我无法弄清楚如何拆分间隔持续时间(并且仍然总结为原始总持续时间).
I was able to adapt the examples in the second link to split everything into intervals but the total duration time is returned and I cannot quite figure out how to get the Interval durations to split (and still sum up to the total original duration).
提前感谢您的见解!
第一次尝试
第二次尝试
推荐答案
sql 小提琴演示
这篇关于将表格分组为 15 分钟间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!