久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

檢測時間戳列中超過 30 分鐘的間隙

Detect gaps over 30 min in timestamp column(檢測時間戳列中超過 30 分鐘的間隙)
本文介紹了檢測時間戳列中超過 30 分鐘的間隙的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經閱讀并嘗試使用標準的間隙和孤島檢測方法,但沒有成功,因為我需要能夠忽略任何少于 30 分鐘的間隙.由于性能問題,我無法使用游標.

I have read up on and attempted using the standard method of gaps and island detection in a series with no success because I need to be able to ignore any gaps less than 30 minutes. I can not use a cursor due to performance issues.

每次有至少 30 分鐘的間隔時,我都需要一個新的行以開始和結束.如果沒有至少 30 的間隔,則結果將是具有時間戳的最小值和最大值的一行.如果有 1 個至少 30 的間隙,則將有 2 行 - 從系列的開始到間隙以及從間隙到結尾.如果有更多的間隙,我們會為間隙之間的每個間隔獲取行,等等.

Everytime there is a gap of at least 30 min, I need a new row with the start and end. If there are no gaps of at least 30, result would be one row with the min and max of the timestamps. If there is 1 gap of at least 30, there would be 2 rows - from the start of the series to the gap and from the gap to the end. If there are more gaps, we get rows for each interval between the gaps, etc.

輸入:

timestamp 

2015-07-15 15:01:21 
2015-07-15 15:17:44 
2015-07-15 15:17:53 
2015-07-15 15:18:34 
2015-07-15 15:21:41 
2015-07-15 15:58:12 
2015-07-15 15:59:12 
2015-07-15 16:05:12
2015-07-15 17:02:12

所需的輸出:

from | to

2015-07-15 15:01:21 | 2015-07-15 15:21:41 
2015-07-15 15:58:12 | 2015-07-15 16:05:12
2015-07-15 17:02:12 | 2015-07-15 17:02:12

推薦答案

使用公用表表達式的簡單解決方案.如果您至少有 1000 行,則與游標性能進行比較.

Easy solution using common table expression. Compare with cursor performance if you have at least 1000 rows.

create table #tmp (Dt datetime)

insert into #tmp values 
('2015-07-15 15:01:21'),
('2015-07-15 15:17:44'), 
('2015-07-15 15:17:53'), 
('2015-07-15 15:18:34'), 
('2015-07-15 15:21:41'), 
('2015-07-15 15:58:12'), 
('2015-07-15 15:59:12'), 
('2015-07-15 16:05:12'),
('2015-07-15 17:02:12')

;with tbl as (
select dt, row_number() over(order by dt) rn
from #tmp
)
select t1.dt [from],t2.dt [to], datediff(minute,t1.dt,t2.dt) gap
from tbl t1 
inner join tbl t2 on t1.rn+1 = t2.rn
where datediff(minute,t1.dt,t2.dt) >30

這篇關于檢測時間戳列中超過 30 分鐘的間隙的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 这里精品 | 免费毛片网站 | 欧美区在线观看 | 91看片在线观看 | 日韩成人免费av | 精品视频久久久久久 | 国产精品久久久久久久 | 亚洲欧美一区二区三区1000 | 中文字幕av亚洲精品一部二部 | 精品一区二区av | 国产在线精品一区二区三区 | 亚洲天堂影院 | 久久综合伊人 | 欧美日韩视频在线第一区 | 国产精品色一区二区三区 | 欧美在线国产精品 | 欧美日韩三级在线观看 | 亚洲欧美成人影院 | 日韩在线一区二区三区 | 91资源在线| 久久精品中文 | 精品国产乱码久久久久久丨区2区 | 一区二区成人在线 | 在线免费视频一区 | 亚洲一区二区三区在线视频 | 欧美不卡一区二区三区 | 欧洲精品码一区二区三区免费看 | 日韩在线免费播放 | 国产视频久久 | 国产精品日韩一区 | 亚洲精品久久久一区二区三区 | 亚洲精品电影网在线观看 | www.一区二区 | 日韩中文字幕av | 日韩在线免费 | www国产成人免费观看视频,深夜成人网 | 91久久爽久久爽爽久久片 | 久久久av| 午夜影院在线观看免费 | 美女天堂av| 亚洲国产精品一区二区第一页 |