mb1124early-Distribution of useres usd Profits and Loss
    Updated 2022-10-27
    WITH sell AS(
    SELECT CASE
    WHEN NFT_ADDRESS='0xb8df6cc3050cc02f967db1ee48330ba23276a492' THEN 'Optipunks'
    WHEN NFT_ADDRESS='0x0110bb5739a6f82eafc748418e572fc67d854a0f' THEN 'Early optimism'
    END AS type,
    seller_address AS sellers,
    COUNT (DISTINCT TX_HASH) AS TX_Count,
    COUNT (DISTINCT TOKENID) AS Tokens_Count,
    sum (price_usd) AS USDPrice,
    sum (price) AS EthPrice
    FROM optimism.core.ez_nft_sales
    WHERE SELLER_ADDRESS != '0x0000000000000000000000000000000000000000'
    AND price is not null AND PRICE_USD is not null AND EVENT_TYPE='sale'
    GROUP BY 1,2
    )
    ,buy AS(
    SELECT CASE
    WHEN NFT_ADDRESS='0xb8df6cc3050cc02f967db1ee48330ba23276a492' THEN 'Optipunks'
    WHEN NFT_ADDRESS='0x0110bb5739a6f82eafc748418e572fc67d854a0f' THEN 'Early optimism'
    END AS type,
    buyer_address AS buyers,
    COUNT (DISTINCT TX_HASH) AS TX_Count,
    COUNT (DISTINCT TOKENID) AS Tokens_Count,
    sum (price_usd) AS USDPrice,
    sum (price) AS EthPrice
    FROM optimism.core.ez_nft_sales
    WHERE BUYER_ADDRESS != '0x0000000000000000000000000000000000000000'
    AND price is not null AND PRICE_USD is not null AND EVENT_TYPE='sale'
    GROUP BY 1,2
    )
    , final AS (
    SELECT sellers AS userr ,
    sum(s.USDPrice - b.USDPrice) AS USD_Profit,
    Run a query to Download Data