Updated 2022-02-08
    with validators as (
    select delegator_address , operator_address from terra.validator_labels
    group by 1,2
    )
    ,
    adressess_LUNA_balance as (
    select address , sum(balance) as Luna_balance from terra.daily_balances
    where date = (select max(date) from terra.daily_balances)
    and currency='LUNA'
    and address_label is NULL
    group by 1
    -- EXCEPT (select operator_address from validators)
    ),
    adressess_LUNA_balance_final as (
    select address , Luna_balance from adressess_LUNA_balance
    EXCEPT
    select delegator_address as address ,Luna_balance from validators INNER join adressess_LUNA_balance
    on validators.delegator_address = adressess_LUNA_balance.address
    EXCEPT
    select operator_address as address ,Luna_balance from validators INNER join adressess_LUNA_balance
    on validators.operator_address = adressess_LUNA_balance.address
    EXCEPT
    select adressess_LUNA_balance.address as address ,Luna_balance from terra.labels INNER join adressess_LUNA_balance
    on terra.labels.address = adressess_LUNA_balance.address
    )
    ,
    active_wallets as (
    select
    case when luna_balance bETWEEN 0 and 1 then '0-1'
    when luna_balance BETWEEN 1 and 100 then '1-100'
    when luna_balance BETWEEN 101 and 200 then '101-200'
    when luna_balance BETWEEN 201 and 300 then '201-300'
    when luna_balance BETWEEN 301 and 400 then '301-400'
    when luna_balance BETWEEN 401 and 500 then '401-500'
    when luna_balance BETWEEN 501 and 1000 then '501-1000'
    when luna_balance BETWEEN 1001 and 2000 then '1001-2000'
    Run a query to Download Data