nitsAnchor Dominance Active
    Updated 2022-02-12
    with active_wallets as (select DISTINCT msg_value:sender from terra.msgs
    where block_timestamp> CURRENT_DATE -30
    ),
    total_balances as
    (
    (select address, sum(balance_usd) as total_balance from terra.daily_balances
    where date = CURRENT_DATE-1 and address in (select * from active_wallets)
    GROUP BY 1 )
    )

    SELECT distribution, avg(percent_balance) as avg_percent_balance, median(percent_balance) as median_percent_balance, sum(anc_balance) as total_anc_balance, sum(total_balance) as total_amt from
    (SELECT *, anc_balance/total_balance*100 as percent_balance,
    case when total_balance < 100 then 'less than 100'
    when total_balance >=pow(10,2) and total_balance < pow(10,3) then '100-1k'
    when total_balance >=pow(10,3) and total_balance < pow(10,4) then '1k-10k'
    when total_balance >=pow(10,4) and total_balance < pow(10,5) then '10k-100k'
    when total_balance >=pow(10,5) and total_balance < pow(10,6) then '100k-1M'
    when total_balance >=pow(10,6) then '1M+' end as distribution
    from
    (SELECT * from (SELECT address as addr,sum(balance_usd) as anc_balance from terra.daily_balances
    where currency = 'ANC' and date = CURRENT_DATE -1 and balance_usd > 10
    GROUP by 1 )
    inner join total_balances
    on address = addr) )
    GROUP by 1
    limit 100

    Run a query to Download Data