add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE t
("id" int, "dt" datetime)
;
INSERT INTO t
("id", "dt")
VALUES
(12345, '2022-08-25 08:45:00'),
(12345, '2022-08-25 09:45:00'),
(12345, '2022-08-25 13:00:00'),
(12345, '2022-08-25 13:30:00'),
(23456, '2022-08-25 10:00:00'),
(23456, '2022-08-25 11:00:00')
6 rows affected
select id
,date
,date2
from (
select id
,dt as "date"
,lead(dt) over (partition by id order by dt) as "date2"
,row_number() over (partition by id order by dt) as rn
from t
) t
where rn % 2 != 0
order by id
id date date2
12345 2022-08-25 08:45:00.000 2022-08-25 09:45:00.000
12345 2022-08-25 13:00:00.000 2022-08-25 13:30:00.000
23456 2022-08-25 10:00:00.000 2022-08-25 11:00:00.000