with tb1 as ( select min(a.block_timestamp) as min_date,
b.PUBKEY_SCRIPT_ADDRESS as user
from bitcoin.core.fact_outputs a left outer join bitcoin.core.fact_inputs b on a.tx_id = b.tx_id
where a.PUBKEY_SCRIPT_ADDRESS = 'bc1qw8wrek2m7nlqldll66ajnwr9mh64syvkt67zlu'
group by 2)
,
tb2 as ( select count(DISTINCT user) as new_users
from tb1
where min_date >= current_date - 30
)
,
tb3 as ( select
count(DISTINCT b.PUBKEY_SCRIPT_ADDRESS) as uniqe_users
from bitcoin.core.fact_outputs a left outer join bitcoin.core.fact_inputs b on a.tx_id = b.tx_id
where a.PUBKEY_SCRIPT_ADDRESS = 'bc1qw8wrek2m7nlqldll66ajnwr9mh64syvkt67zlu'
)
select uniqe_users as total_users, new_users
from tb2, tb3