with blocktime as (
select
a.block_timestamp as block_timestamp,
datediff(second, b.block_timestamp, a.block_timestamp) as block_time
from terra.core.fact_transactions as a
inner join terra.core.fact_transactions as b on a.block_id = b.block_id + 1
where a.block_timestamp >= current_date - 365
)
select
date_trunc('week', block_timestamp) as week,
avg(block_time) as avg_blocktime
from blocktime
group by week
order by week asc