pine_saminfl all day sales
    Updated 2022-12-05
    with pricet as (
    select timestamp::date as day,
    avg (price_usd) as usdprice
    from flow.core.fact_prices
    where symbol = 'FLOW'
    group by 1)

    select CASE WHEN block_timestamp >= '2022-11-24' THEN 'AFTER THANKSGIVING' ELSE 'BEFORE THANKSGIVING' END AS THANKSGIVINGtime,
    DATE_TRUNC('day', block_timestamp) AS date,
    count (distinct date) as number_of_days,
    count (distinct tx_id) as Sales,
    count (distinct buyer) as Buyers,
    Buyers/number_of_days as "Average Buyers/Day",
    count (distinct seller) as Sellers,
    count (distinct nft_id) as NFTs,
    sum (case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as Total_USD_Volume,
    avg (case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as Average_USD_Volume,
    median (case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as Median_USD_Volume,
    min (case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as Minimum_USD_Volume,
    max (case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as Maximum_USD_Volume,
    sum (sales) over (order by date) as Cumulative_Sales,
    sum (total_usd_volume) over (order by date) as Cumulative_Sales_USD,
    avg (Total_USD_Volume) over (order by date rows between 7 PRECEDING and current row) as Moving_Average
    from flow.core.ez_nft_sales a join pricet b on a.block_timestamp::Date = b.day
    where nft_collection = 'A.e4cf4bdc1751c65d.AllDay'
    and tx_succeeded = 'TRUE'
    group by 1,2