Используя LEAD()
с CASE
, вы можете получить ожидаемый результат:
SELECT ResultDate FROM (
SELECT CASE WHEN (DATEDIFF(MINUTE, LEAD(EntryDate, 1) OVER(ORDER BY EntryDate),EntryDate) < -1) THEN DATEADD(MINUTE, +1, EntryDate) END AS ResultDate
FROM TableName
) Q WHERE ResultDate IS NOT NULL
Демонстрация с данными образца:
DECLARE @TestTable TABLE (Id INT, EntryDate DATETIME);
INSERT INTO @TestTable (Id, EntryDate) VALUES
(8093562, '2019-05-17 15:01:25.000'),
(8093563, '2019-05-17 15:02:25.000'),
(8093564, '2019-05-17 15:03:25.000'),
(8093565, '2019-05-17 15:04:25.000'),
(8093566, '2019-05-17 15:05:25.000'),
(8093568, '2019-05-17 15:07:25.000'),
(8093569, '2019-05-17 15:08:25.000'),
(8093780, '2019-05-17 15:09:25.000'),
(8093781, '2019-05-17 15:10:25.000');
SELECT ResultDate FROM (
SELECT CASE WHEN (DATEDIFF(MINUTE, LEAD(EntryDate, 1) OVER(ORDER BY EntryDate),EntryDate) < -1) THEN DATEADD(MINUTE, +1, EntryDate) END AS ResultDate
FROM @TestTable
) Q WHERE ResultDate IS NOT NULL
Вывод:
ResultDate
-----------------------
2019-05-17 15:06:25.000
Демонстрация по дб <> fiddle