with sender as ( select min(block_timestamp::date) as date, tx_sender
from terra.core.fact_transactions
group by 2)
,
new_user as ( select DISTINCT tx_sender
from sender
where date >= CURRENT_DATE - 60)
select date(block_timestamp) as date, 'New User' as type, count(DISTINCT(tx_id)) as total_tx,
sum(total_tx) over (order by date asc) as cum_tx
from terra.core.fact_transactions
where tx_sender in (select tx_sender from new_user)
and block_timestamp >= CURRENT_DATE - 60
group by 1
UNION
select date(block_timestamp) as date, 'Old User' as type, count(DISTINCT(tx_id)) as total_tx,
sum(total_tx) over (order by date asc) as cum_tx
from terra.core.fact_transactions
where tx_sender not in (select tx_sender from new_user)
and block_timestamp >= CURRENT_DATE - 60
group by 1