我有一个用户活动表。我想在几分钟内看到每个过程之间的差异。
更具体地说,这里是表中的部分数据。

Date                |TranType|   Prod          |    Loc
-----------------------------------------------------------
02/27/12 3:17:21 PM | PICK   | LIrishGreenXL   |     E01C015
02/27/12 3:18:18 PM | PICK   | LAntHeliconiaS  |     E01A126
02/27/12 3:19:00 PM | PICK   | LAntHeliconiaL  |     E01A128
02/27/12 3:19:07 PM | PICK   | LAntHeliconiaXL |     E01A129


我想以分钟为单位来检索第一和第二个过程之间的时差,而不是第二和第三个之间的时差....
谢谢

最佳答案

这样的事情将在MS SQL中起作用,只需更改字段名称以匹配您的字段名称即可:



select a.ActionDate, datediff(minute,a.ActionDate,b.ActionDate) as DiffMin

(select ROW_NUMBER() OVER(ORDER BY ActionDate) AS Row, ActionDate
from [dbo].[Attendance]) a

inner join

(select ROW_NUMBER() OVER(ORDER BY ActionDate) AS Row, ActionDate
from [dbo].[Attendance]) b

on a.Row +1  = b.Row 

07-26 02:49