yasmin-n-d-r-hGarageCard
    Updated 2023-10-14
    -- forked from Barbie @ https://flipsidecrypto.xyz/edit/queries/f53c2422-0ae2-4299-8307-074b0575c45b

    WITH sales_summary AS (
    SELECT
    COUNT(DISTINCT CASE WHEN tx_succeeded = 'true' THEN tx_id END) AS sales_tx,
    COUNT(DISTINCT CASE WHEN tx_succeeded = 'true' THEN buyer END) AS buyers,
    COUNT(DISTINCT CASE WHEN tx_succeeded = 'true' THEN seller END) AS sellers,
    COUNT(DISTINCT CASE WHEN tx_succeeded = 'true' THEN nft_id END) AS tokens_sold,
    SUM(CASE WHEN tx_succeeded = 'true' THEN price * p.prices ELSE 0 END) AS amount,
    AVG(CASE WHEN tx_succeeded = 'true' THEN price * p.prices ELSE 0 END) AS avg_amount,
    MIN(CASE WHEN tx_succeeded = 'true' THEN price * p.prices ELSE 0 END) AS floor_price,
    MAX(CASE WHEN tx_succeeded = 'true' THEN price * p.prices ELSE 0 END) AS max_sales_amount
    FROM flow.nft.ez_nft_sales s
    JOIN (
    SELECT recorded_hour::date AS date1, AVG(close) AS prices
    FROM flow.price.fact_hourly_prices
    WHERE token = 'Flow'
    GROUP BY 1
    ) p ON s.block_timestamp::date = p.date1::date
    WHERE nft_collection LIKE '%GarageCard%'
    )
    SELECT * FROM sales_summary;


    Run a query to Download Data