with initial_data as
(
select
block_number,
block_timestamp,
tx_count,
LAG(block_timestamp,1) OVER (ORDER BY block_timestamp) previous_block_timestamp,
DATEDIFF(second, previous_block_timestamp, block_timestamp) as previous_block_length
from polygon.core.fact_blocks
)
select
previous_block_length as block_length,
count(distinct block_number) as number_of_blocks
from initial_data
where block_length is not null
group by previous_block_length