AS
Size: a a a
AS
AS
AS
TS
Дt
F
F
G
Дt
AS
with
test as (select 0 as id UNION select 1 UNION select 4 UNION select 10 UNION select 14 UNION select 16 UNION select 20 UNION select 27
UNION select 28 UNION select 29)
,prepare_1 as (
select
id
,case when (lag(id) over(order by id) + 5 < id) then 'begin'
when lag(id) over(order by id) is null then 'first_begin' end as begin_flag
,case when (lead(id) over(order by id) - 5 > id) then 'end'
when lead(id) over(order by id) is null then 'last_end' end as end_flag
from
test
)
,prepare_2 as (
select
*
,case when begin_flag is not null then id else lead(id) over(order by id) end as start_id
,case when end_flag is null then lead(id) over(order by id) end as end_id
-- ,case when end_flag is null then id end as end_id
from
prepare_1
where begin_flag is not null or end_flag is not null
)
select start_id, end_id
from
prepare_2
where
start_id is not null
and end_id is not null
ВТ
with
test as (select 0 as id UNION select 1 UNION select 4 UNION select 10 UNION select 14 UNION select 16 UNION select 20 UNION select 27
UNION select 28 UNION select 29)
,prepare_1 as (
select
id
,case when (lag(id) over(order by id) + 5 < id) then 'begin'
when lag(id) over(order by id) is null then 'first_begin' end as begin_flag
,case when (lead(id) over(order by id) - 5 > id) then 'end'
when lead(id) over(order by id) is null then 'last_end' end as end_flag
from
test
)
,prepare_2 as (
select
*
,case when begin_flag is not null then id else lead(id) over(order by id) end as start_id
,case when end_flag is null then lead(id) over(order by id) end as end_id
-- ,case when end_flag is null then id end as end_id
from
prepare_1
where begin_flag is not null or end_flag is not null
)
select start_id, end_id
from
prepare_2
where
start_id is not null
and end_id is not null
ВТ
ВТ
ВТ
ВТ
ВТ
ВТ