Updated 2025-03-06
    with tab1 as (
    select
    block_timestamp,
    tx_hash,
    to_address as wallet,
    'in' as tx_type,
    amount

    from ink.core.ez_token_transfers
    where contract_address like lower('0xF1815bd50389c46847f0Bda824eC8da914045D14')
    --and to_address like '0x0000000000000000000000000000000000000000'

    union all

    select
    block_timestamp,
    tx_hash,
    from_address as wallet,
    'out' as tx_type,
    amount

    from ink.core.ez_token_transfers
    where contract_address like lower('0xF1815bd50389c46847f0Bda824eC8da914045D14')
    --and like '0x0000000000000000000000000000000000000000'
    )

    select
    wallet,
    sum(
    case when tx_type like 'in' then amount else -amount end
    ) as balance

    from tab1
    group by 1
    order by 2 desc

    QueryRunArchived: QueryRun has been archived