SQL Select语句,返回来自同一个表的下一个日期时间的分钟差异(SQL Select statements that returns differences in minutes from ne

编程入门 行业动态 更新时间:2024-10-27 16:30:05
SQL Select语句,返回来自同一个表的下一个日期时间的分钟差异(SQL Select statements that returns differences in minutes from next date-time from the same table)

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

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

我想在几分钟内检索时差,在第一个和第二个过程之间,而不是第二个和第三个过程....谢谢

I have a user activity table. I want to see a difference between each process in minutes. To be more specific here is a partial data from table.

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

I want to retrieve time difference in minutes, between first and second process, than second and third and .... Thank you

最满意答案

这样的东西将在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  
  
 

Something like this will work in MS SQL, just change the field names to match yours:

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  
  
 

更多推荐

本文发布于:2023-07-15 11:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1112866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   差异   日期   时间   Select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!