Eman-RazAverage Balance per Wallet
    Updated 2024-09-08
    with final_table as (
    ------------------------------arb----------------------------
    with arb as (with tab6 as (with tab4 as (with tab3 as (with tab1 as (select to_address, sum(amount) as input_vol
    from arbitrum.core.ez_token_transfers
    where contract_address='0x58b9cb810a68a7f3e1e4f8cb45d1b9b3c79705e8'
    group by 1),

    tab2 as (select from_address, sum(amount) as output_vol
    from arbitrum.core.ez_token_transfers
    where contract_address='0x58b9cb810a68a7f3e1e4f8cb45d1b9b3c79705e8'
    group by 1)

    select to_address as address, case
    when input_vol is null then 0 else input_vol end as input_volume, case
    when output_vol is null then 0 else output_vol end as output_volume
    from tab1 left join tab2 on tab1.to_address=tab2.from_address)

    select address, input_volume AS "Input Volume", output_volume AS "Output Volume",
    input_volume-output_volume as "Balance"
    from tab3
    ORDER BY 4 DESC),

    tab5 as (select address, ADDRESS_name
    from arbitrum.core.dim_labels)

    select tab4.address as ADDRESS, address_name, "Input Volume", "Output Volume", "Balance"
    from tab4 left join tab5 on tab4.address=tab5.address
    --where tab4.address not in ('0x2a82ae142b2e62cb7d10b55e323acb1cab663a26'
    --,'0x2501c477d0a35545a387aa4a3eee4292a9a8b3f0')
    order by 5 desc)

    select "Balance"
    from tab6
    where "Balance">0),

    ------------------------------op-----------------------------
    Auto-refreshes every 3 hours
    QueryRunArchived: QueryRun has been archived