tomingTop NFT Traders' Profit over last 30 days copy
    -- forked from Ario / Top NFT Traders' Profit over last 30 days @ https://flipsidecrypto.xyz/Ario/q/6Uu7O8FaNDKz/top-nft-traders-profit-over-last-30-days

    WITH buy as (
    select
    BLOCK_TIMESTAMP,
    BUYER_ADDRESS,
    NFT_ADDRESS,
    TOKENID,
    PRICE_USD as Buy_Price
    from ethereum.core.ez_nft_sales
    where BLOCK_TIMESTAMP::date >= current_date - 30
    and PRICE_USD is not null
    and EVENT_TYPE = 'sale'
    ),
    sell as (
    select
    BLOCK_TIMESTAMP,
    seller_ADDRESS,
    NFT_ADDRESS,
    TOKENID,
    PRICE_USD as Sell_Price
    from ethereum.core.ez_nft_sales
    where BLOCK_TIMESTAMP::date >= current_date - 30
    and PRICE_USD is not null
    and EVENT_TYPE = 'sale'
    )
    select
    seller_ADDRESS as Trader,
    sum(Sell_Price - Buy_Price) as Profit_USD
    from sell a join buy b on a.seller_ADDRESS = b.BUYER_ADDRESS and a.NFT_ADDRESS = b.NFT_ADDRESS and a.TOKENID = b.TOKENID
    and a.BLOCK_TIMESTAMP > b.BLOCK_TIMESTAMP
    group by 1
    order by 2 desc
    limit 10


    Run a query to Download Data