Updated 2022-10-03
    with buytable as (
    select buyer_address as Buyers,
    count (distinct tx_hash),
    count (distinct tokenid) as Tokens_Count,
    sum (price_usd) as USD_Value,
    sum (price) as ETH_Value
    FROM ethereum.core.ez_nft_sales
    where EVENT_TYPE = 'sale' and CURRENCY_SYMBOL = 'ETH' and NFT_ADDRESS=lower('0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e')and price_usd > 0 and price > 0
    group by 1),

    selltable as (
    select seller_address as Seller,
    count (distinct tx_hash),
    count (distinct tokenid) as Tokens_Count,
    sum (price_usd) as USD_Value,
    sum (price) as ETH_Value
    FROM ethereum.core.ez_nft_sales
    where EVENT_TYPE = 'sale' and CURRENCY_SYMBOL = 'ETH' and NFT_ADDRESS=lower('0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e')and price_usd > 0 and price > 0
    group by 1),

    maintable as (
    select buyers as Trader,
    sum (t2.usd_value - t1.usd_value) as USD_Profit,
    sum (t2.ETH_Value - t1.ETH_Value) as ETH_Profit
    from buytable t1 join selltable t2 on buyers = seller
    group by 1)

    select case when ETH_Profit > 0 then 'Profit'
    when ETH_Profit < 0 then 'Loss'
    when ETH_Profit = 0 then 'No Profit No Loss'
    end as type,ETH_Profit,
    case when USD_Profit > 0 then 'Profit'
    when USD_Profit < 0 then 'Loss'
    when USD_Profit = 0 then 'No Profit No Loss'
    end as typeS,USD_Profit,