justabfjWeekly Sale Stats
    Updated 2022-10-23
    with nft_sales as (
    select block_timestamp,
    tx_id,
    nft_id,
    buyer,
    seller,
    (case
    when currency = 'A.1654653399040a61.FlowToken' then price * avg_price
    else price * 1
    end) as usd_price
    from flow.core.ez_nft_sales
    join (
    select date_trunc('day', timestamp) as day,
    avg(price_usd) as avg_price
    from flow.core.fact_prices
    where symbol = 'FLOW'
    group by day
    ) tokn_price on day = block_timestamp::date
    where nft_collection = 'A.329feb3ab062d289.RaceDay_NFT'
    and tx_succeeded = true
    ),
    weekly_sales as (
    select date_trunc('week', block_timestamp) as week,
    'Secondary Sale' as type,
    count(distinct tx_id) as sales_count,
    count(distinct buyer) as total_unique_buyers,
    count(distinct nft_id) as nfts_count,
    sum(usd_price) as total_USD_sales,
    avg(usd_price) as avg_USD_sale_price
    from nft_sales
    group by week, type
    ),
    weekly_cumulative_stats as (
    select week,
    sum(sales_count) over (partition by type order by week) as total_sales_count,
    sum(total_unique_buyers) over (partition by type order by week) as total_unique_buyers,
    Run a query to Download Data