WITH
differences as (
SELECT
distinct block_number,
block_timestamp,
LAG(block_timestamp) IGNORE NULLS OVER (ORDER BY block_number) as last_date,
datediff(SECOND,block_timestamp,last_date) as difference
from ethereum.core.fact_blocks
order by 2 DESC
)
select
avg(abs(difference)) as avg_time,
max(abs(difference)) as max_time,
min(abs(difference)) as min_time
from differences