with active_wallets as ( select tx_sender,
count(DISTINCT tx_id) as count_tx
from terra.core.fact_transactions
where tx_succeeded=TRUE
group by 1
having count_tx > {{TransactionCount}})
,
main as ( select
tx_sender,
count(DISTINCT tx_id) as tx
from terra.core.fact_transactions
where tx_sender in (select tx_sender from active_wallets)
group by 1)
select
tx_sender,
sum(tx) as tx_by_active_wallets
from main
group by 1
order by 2 DESC
limit 10