我在 SQL Server 中有这种数据
Person StartDate EndDate Value
-----------------------------------------------------------------
38523 2013-01-10 22:00:00.000 2013-01-10 22:59:00.000 0.064
38523 2013-01-10 23:00:00.000 2013-01-10 23:59:00.000 0.065
38523 2013-01-12 00:00:00.000 2013-01-12 00:59:00.000 0.068
38523 2013-01-12 01:00:00.000 2013-01-12 01:59:00.000 0.069
38523 2013-01-12 02:00:00.000 2013-01-12 02:59:00.000 0.069
38523 2013-01-12 03:00:00.000 2013-01-12 03:59:00.000 0.069
38523 2013-01-31 23:00:00.000 2013-01-31 23:59:00.000 0.061
38523 2013-02-01 00:00:00.000 2013-02-01 00:59:00.000 0.064
我需要以这样的方式进行分组,即每月应将连续值组合在一起。如果上一个结束日期和下一个开始日期之间的间隔超过 1 分钟,则应将其分成单独的组。
预期结果:
Person StartDate EndDate Sum(Value)
----------------------------------------------------------------------
38523 2013-01-10 22:00:00.000 2013-01-10 23:59:00.000 0.129
38523 2013-01-12 00:00:00.000 2013-01-12 03:59:00.000 0.275
38523 2013-01-31 23:00:00.000 2013-01-31 23:59:00.000 0.061 (even though continuity exists, month was end hence separate record)
38523 2013-02-01 00:00:00.000 2013-02-01 00:59:00.000 0.064
任何帮助表示赞赏。