jackguyWallets by AREO Balance 2
    Updated 2025-02-10
    SELECT
    count(*) as users,
    median(balance),
    avg(balance)


    FROM (
    SELECT
    user as wallet,
    sum(CASE when tx_type LIKE 'in' then amt else -1 * amt end) as balance

    FROM (
    SELECT
    FROM_address as user,
    'out' as tx_type,
    sum(raw_amount / power(10, 18)) as amt
    FROM base.core.fact_token_transfers
    WHERE contract_address LIKE lower('0x940181a94A35A4569E4529A3CDfB74e38FD98631')
    GROUP BY 1,2

    UNION

    SELECT
    to_address as user,
    'in' as tx_type,
    sum(raw_amount / power(10, 18)) as amt
    FROM base.core.fact_token_transfers
    WHERE contract_address LIKE lower('0x940181a94A35A4569E4529A3CDfB74e38FD98631')
    GROUP BY 1,2
    )
    GROUP BY 1

    HAVING balance > 0
    ORDER BY 2 DESC
    )