with blocks as (
select
'Flow' as network,
a.block_timestamp,
a.tx_count,
DATEDIFF('millisecond', a.block_timestamp, b.block_timestamp) as duration
from
flow.core.fact_blocks a
join flow.core.fact_blocks b on a.id = b.parent_id
where
a.tx_count > 0
)
select
network,
duration,
tx_count,
count(*) as cnt
from
blocks
group by
network, duration, tx_count
order by
network, duration, tx_count