mattkstew1 FLOW OA
    Updated 2023-06-03
    with tab1 as (
    select
    buyer,
    nft_collection,
    nft_ID,
    price as buy_price,
    1 AS is_buyer
    FROM flow.core.ez_nft_sales
    where block_timestamp > current_date - 90
    )

    , tab2 as (
    select
    seller,
    nft_collection,
    nft_ID,
    price as sell_price,
    0 AS is_buyer
    FROM flow.core.ez_nft_sales
    where block_timestamp > current_date - 90
    )

    , tab3 as (
    select
    buyer,
    sum(sell_price - buy_price) as net_profit

    from tab1 left outer join tab2
    on buyer = seller and tab1.nft_id = tab2.nft_id
    group by 1
    )


    select
    COUNT_IF(Net_Profit > 0) AS "Profitable Traders",
    COUNT_IF(Net_Profit < 0) AS "Non-Profitable Traders",
    Run a query to Download Data