libruaryFloor price combined
    Updated 2024-11-14
    WITH WeeklySales AS (
    SELECT
    block_timestamp,
    nft_id,
    price AS sale_price
    FROM
    flow.nft.ez_nft_sales
    WHERE
    nft_collection = 'A.0b2a3299cc857e29.TopShot' -- Only include TopShot NFT sales
    AND price <= 20.0 -- Only include sales of $20 or less
    AND tx_succeeded = TRUE -- Only include successful transactions
    ),

    -- Ranking sales per week and excluding the bottom 2% of sales
    RankedSales AS (
    SELECT
    DATE_TRUNC('week', block_timestamp) AS activity_week,
    sale_price,
    PERCENT_RANK() OVER (
    PARTITION BY DATE_TRUNC('week', block_timestamp)
    ORDER BY sale_price ASC
    ) AS price_rank
    FROM
    WeeklySales
    ),

    -- Exclude bottom 2% of sales and find the floor price for ez_nft_sales
    WeeklyFloorPrice AS (
    SELECT
    activity_week,
    MIN(sale_price) AS floor_price -- The lowest valid sale price per week
    FROM
    RankedSales
    WHERE
    price_rank > 0.02 -- Exclude the lowest 2% of sales (outliers)
    GROUP BY
    QueryRunArchived: QueryRun has been archived