Updated 2022-12-09
    with buytable1 as (
    select buyer_address, tx_hash, tokenid, price_usd,price
    FROM ethereum.core.ez_nft_sales
    WHERE EVENT_TYPE = 'sale' and CURRENCY_SYMBOL = 'ETH'
    and lower(NFT_ADDRESS)=lower('0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d')
    and price_usd > 0 and price > 0),

    selltable1 as (
    select seller_address, tx_hash, tokenid, price_usd,price
    FROM ethereum.core.ez_nft_sales
    WHERE EVENT_TYPE = 'sale' and CURRENCY_SYMBOL = 'ETH'
    and lower(NFT_ADDRESS)=lower('0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d')
    and price_usd > 0 and price > 0)

    select
    buyer_address,-USD_Profit as USD_Profit,-ETH_Profit as ETH_Profit
    from
    (select buyer_address,
    sum (t2.price_usd - t1.price_usd) as USD_Profit,
    sum (t2.price - t1.price) as ETH_Profit
    from buytable1 t1 join selltable1 t2 on buyer_address = seller_address and t1.tokenid = t2.tokenid
    group by 1
    order by 3 asc
    limit 10)
    Run a query to Download Data