with cte as (
select *,
lead(sampleDate, 1, sampleDate) over (order by sampleDate) as nextDate,
CAST(strftime('%M', lead(sampleDate, 1, sampleDate) over (order by sampleDate)) as integer)
- CAST(strftime('%M', sampleDate) as integer) as diff
from mytable
)
select sampleDate, nextDate
from cte
where diff > 1
with cte as (
select 4556 id, datetime('2023-03-20 12:54:27') sampleDate
union ALL
select 4557 id, datetime('2023-03-20 12:55:27') sampleDate
union ALL
select 4558 id, datetime('2023-03-20 12:56:27') sampleDate
union ALL
select 4559 id, datetime('2023-03-29 10:46:46') sampleDate
union ALL
select 4560 id, datetime('2023-10-06 10:52:47') sampleDate
union ALL
select 4561 id, datetime('2023-10-06 10:53:47') sampleDate
)
select a.* from cte a
left join cte b ON b.sampledate = datetime(a.sampleDate,'+1 minutes') -- if wanted the gap to be exact one minutes
-- ON b.sampledate between datetime(a.sampleDate,'+1 seconds') and datetime(a.sampleDate,'+1 minutes') -- if you wanted the gap to be anywhere under a minute
where b.id is NULL
2条答案
按热度按时间zsohkypk1#
您可以使用
LEAD()
函数来检索下一个日期,然后计算差值来检索间隙:n3ipq98p2#
或者你可以使用一个左反连接来获取没有下一分钟记录的行吗?示例如下-