MLDZMNTWN16
    Updated 2023-02-16
    with tb1 as (select
    distinct TX_RECEIVER as user1,
    sum(DEPOSIT/1e24) as total_recieved
    from near.core.fact_transfers
    where STATUS = 'TRUE'
    group by 1),

    tb2 as (select
    distinct TX_SIGNER as user2,
    sum(DEPOSIT/1e24) as total_sent
    from near.core.fact_transfers s left join tb1 b on s.TX_SIGNER=b.user1
    where STATUS = 'TRUE'
    and TX_SIGNER in (select user1 from tb1)
    group by 1),

    tb3 as (select
    distinct user1 as users,
    total_recieved - total_sent as net_near,
    row_number() over (order by net_near desc) as rank1
    from tb1 s left join tb2 b on s.user1 = b.user2
    left join near.core.dim_address_labels c on s.user1 = c.ADDRESS
    where total_recieved>total_sent
    and ADDRESS_NAME is null
    order by 2 desc limit 20
    ),

    t2 as (
    select
    x.BLOCK_TIMESTAMP,
    x.TX_SIGNER,
    x.tx_hash,
    x.TX_RECEIVER,
    x.DEPOSIT/1e24 as volume
    from near.core.fact_transfers x
    join tb3 y on x.TX_SIGNER = y.users
    where STATUS = 'TRUE'
    Run a query to Download Data