1
12:00:08 01-01-2021 1
12:00:20 01-01-2021 0
12:00:24 01-01-2021 0
12:00:28 01-01-2021 1
12:00:32 01-01-2021 1
12:00:36 01-01-2021 1
Какой запрос можно составить, чтобы получить два интервала, когда значение равно единице?
12:00:00 01-01-2021 - 12:00:08 01-01-2021 И 12:00:28 01-01-2021 - 12:00:36 01-01-202
Запрос с lag()/lead()
как-то так create table test_1 ( date timestamp, value smallint ); insert into test_1 (date, value) values ('01-01-2021 12:00:00',1), ('01-01-2021 12:00:04',1), ('01-01-2021 12:00:08',1), ('01-01-2021 12:00:20',0), ('01-01-2021 12:00:24',0), ('01-01-2021 12:00:28',1), ('01-01-2021 12:00:32',1), ('01-01-2021 12:00:36',1); select min(date), max(date) from ( select *, row_number() over (order by date) - row_number() over (partition by value order by date) as grp from test_1 ) t where value = 1 group by grp;
Обсуждают сегодня