Updated 2024-09-04
    with
    news as (
    SELECT
    distinct event_data:buyer as news,
    min(trunc(block_timestamp,'week')) as debut
    from flow.core.fact_events
    where
    tx_succeeded = true and event_type='ListingCompleted'
    and event_data:nftType='A.699bf284101a76f1.JollyJokers.NFT'
    --and y.event_contract like '%JollyJokers%'
    group by 1
    ),
    data as (
    select *,CAST(event_data:salePrice AS DECIMAL(18,8)) as price from flow.core.fact_events s
    where
    tx_succeeded = true and event_type='ListingCompleted'
    and event_data:nftType='A.699bf284101a76f1.JollyJokers.NFT'
    and event_data:buyer is not null and event_data:salePrice is not null
    and event_data:purchased= 'true'
    )

    select
    trunc(block_timestamp-interval '4 hours','week') as date,
    count(distinct tx_id) as sales_count,
    sum(sales_count) over (order by date) as total_sales,
    sum(price) as sales_volume,
    sum(sales_volume) over (order by date) as total_sales_volume,
    round(avg(price),0) as avg_NFT_price,
    min(price) as floor_price,
    count(distinct event_data:buyer) as unique_buyers--,
    --count(distinct news) as new_buyers,
    --sum(new_buyers) over (order by date) as total_buyers
    from data s
    --left join news on trunc(block_timestamp,'week') = news.debut
    where
    tx_succeeded = true and event_type='ListingCompleted'
    QueryRunArchived: QueryRun has been archived