在Microsoft SQL Server 2012中,我需要删除下面“Flow”列中相邻重复的行,只保留第一行(用*标记以说明)。之后,我需要计算所有行的1和0之间的时间差,并得到总的累积时间。
Record Number Downhole Time Flow
-------------------------------------------
0 03/27/2013 19:23:48.582 1 *
58 03/27/2013 19:28:12.606 1
137 03/27/2013 19:32:16.070 0 *
143 03/27/2013 19:33:59.070 0
255 03/27/2013 19:40:14.070 0
272 03/29/2013 14:43:55.071 1 *
289 03/29/2013 14:45:44.070 1
293 03/29/2013 14:45:59.071 0 *
294 03/29/2013 14:46:10.070 0
删除相邻记录后的结果:
Record Number Downhole Time Flow
-------------------------------------------
0 03/27/2013 19:23:48.582 1 *
137 03/27/2013 19:32:16.070 0 *
272 03/29/2013 14:43:55.071 1 *
293 03/29/2013 14:45:59.071 0 *
期望最终结果
cumulative time difference =
(03/27/2013 19:32:16.070 - 03/27/2013 19:23:48.582)
+ (03/29/2013 14:45:59.071 - 03/29/2013 14:43:55.071)
+ if there are more rows.
Unique
还是最早的Time
? -- “time difference for all rows, each consecutive pair” 指的是所有行之间的时间差异,每个连续的一对是什么意思?你能举个例子吗? - Daniel Sparing