jackguyNEAR Distribution 2 copy
    Updated 2023-10-19
    -- forked from NEAR Distribution 2 @ https://flipsidecrypto.xyz/edit/queries/71c761af-7a6f-4a7f-bab7-15994b64498b

    WITH tab1 as (
    SELECT
    tx_receiver,
    sum(deposit / power(10, 24)) as in_volume
    FROM near.core.fact_transfers
    GROUP BY 1
    ), tab2 as (
    SELECT
    TX_SIGNER,
    sum(deposit / power(10, 24)) as out_volume
    FROM near.core.fact_transfers
    GROUP BY 1
    ), tab3 as (
    SELECT
    *,
    in_volume - out_volume as net_balance
    FROM tab1
    LEFT OUTER join tab2
    on tx_signer = tx_receiver
    HAVING net_balance > 0
    )

    SELECT
    avg(net_balance),
    median(net_balance),
    max(net_balance)
    FROM tab3


    Run a query to Download Data