FatemeTheLadyP3: P total top users Profit
    Updated 2022-07-16
    with l as (
    select address
    from polygon.core.dim_labels
    where label_type='nft'
    and (label_subtype = 'token_contract' or label_subtype = 'general_contract'))
    ,b as (
    select
    to_address as wallet,
    sum(amount_usd) as buy
    from flipside_prod_db.polygon.udm_events u
    join l on l.address = u.contract_address
    where event_name='transfer' and block_timestamp::date>='2022-01-01' and block_timestamp::date<='2022-06-30' and to_address not in ('0x00000000000b69ec332f49b7c4d2b101f93c3bed', '0x0000000000000000000000000000000000000000','0x00000000000b186ebef1ac9a27c7eb16687ac2a9',
    '0x0000000000000000000000000000000000000001','0x000000000000000000000000000000000000dead')
    and amount_usd>0 group by 1)
    ,s as (
    select
    from_address as wallet,
    sum(amount_usd) as sell
    from flipside_prod_db.polygon.udm_events u
    join l on l.address = u.contract_address
    where block_timestamp::date>='2022-01-01' and block_timestamp::date<='2022-06-30' and event_name='transfer' and from_address not in ('0x00000000000b69ec332f49b7c4d2b101f93c3bed', '0x0000000000000000000000000000000000000000','0x00000000000b186ebef1ac9a27c7eb16687ac2a9',
    '0x0000000000000000000000000000000000000001','0x000000000000000000000000000000000000dead')
    and amount_usd>0 group by 1 )
    select b.wallet as User, sum(s.sell - b.buy) as profit_USD from b join s using(wallet)
    group by 1 order by 2 desc
    limit 5
    Run a query to Download Data