本文介绍了第一条记录的结束日期与下一条记录的第一条日期之间的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何找到不同列级别之间以分钟为单位的日期差异
How to find the dates difference in minutes among different columns levels as
No SourceID RecordID Start Date End Date
1 1 1 2009-09-07 09:12:00.0000 2009-09-07 11:00:00.0000
2 1 1 2009-09-07 11:19:00.0000 2009-09-07 12:12:00.0000
3 1 1 2009-09-07 12:23:00.0000 2009-09-07 12:54:00.0000
4 1 1 2009-09-07 13:49:00.0000 2009-09-07 14:45:00.0000
如何获取第一条记录的结束日期与下一条记录的开始日期与最后一条记录的值为NULL的差值.
How to get the difference between EndDate of first record with Start Date of next record and the last record with NULL value.
这里结果需要得到
SourceID RecordID Start Date End Date DiffMin
1 1 2009-09-07 09:12:00.0000 2009-09-07 11:00:00.0000 19
1 1 2009-09-07 11:19:00.0000 2009-09-07 12:12:00.0000 11
1 1 2009-09-07 12:23:00.0000 2009-09-07 12:54:00.0000 55
1 1 2009-09-07 13:49:00.0000 2009-09-07 14:45:00.0000 NULL
谢谢
真话
推荐答案
SELECT SourceId,RecordId,StartDate,EndDate
, DATEDIFF(mi,a.EndDate,b.StartDate) DiffMin
FROM table a
LEFT JOIN table b ON A.no = B.no+1
这篇关于第一条记录的结束日期与下一条记录的第一条日期之间的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!