with list as
(
SELECT *, ROW_NUMBER() OVER (ORDER BY block_timestamp asc) as rn
FROM flow.core.fact_blocks
),
list2 as (
SELECT DATEDIFF(s, o1.block_timestamp, o2.block_timestamp) as diff
FROM list o1 JOIN list o2
ON o1.rn + 1 = o2.rn
)
select min(diff) as min_gap_time, max(diff) as max_gap_time from list2