with blocks_time as (SELECT
block_timestamp as datee,
block_number,
(DATEDIFF(second, lag(datee) ignore nulls over(ORDER BY datee ASC),block_timestamp)) as block_time
FROM polygon.core.fact_blocks
)
select
date_trunc('minute',datee) as date,
avg(block_time) as "AVG_TIME"
from blocks_time
GROUP BY date
ORDER BY date