有如下的表格:
ModifyDate| ModifiedBy | TaskID |
2018-02-05| Bob | 55444 |
2018-02-06| Lily | 55444 |
2018-02-08| Sarah | 55444 |
对于每一行,我需要计算每个TaskID在Modifydate之间的时间差(以天为单位)。
例如,我的输出应如下所示:
ModifyDate| ModifiedBy | TaskID | Time
2018-02-05| Bob | 55444 | 1
2018-02-06| Lily | 55444 | 2
2018-02-08| Sarah | 55444 | NULL
SELECT ModifyDate, ModifiedBy, TaskID,
DATEDIFF(DAY, ModifyDate,
LEAD(ModifyDate) OVER (PARTITION BY TaskID
ORDER BY ModifyDate))
FROM mytable
SELECT date1, time1, column3,column4,column5,column6,
TimeDiff = DATEDIFF(microsecond, time1,
LEAD(time1) OVER (PARTITION BY column3
ORDER BY time1))
INTO [dbo].[f51bd700]
FROM [dbo].[f51bd700-1]