winnie-fsSolana Rolling Avg Sales Volume copy
    Updated 2024-09-04
    -- forked from kellen / Solana Rolling Avg Sales Volume @ https://flipsidecrypto.xyz/kellen/q/xevV9x-3WMUT/solana-rolling-avg-sales-volume


    with p as (
    select hour::date as date
    , avg(price) as avg_price
    from crosschain.price.ez_prices_hourly
    where hour >= '2021-01-01'
    and token_address in (
    'So11111111111111111111111111111111111111112'
    )
    group by 1
    ), t0 as (
    select date_trunc('day', BLOCK_TIMESTAMP) as date
    , count (distinct tx_id) as n_sales
    , count (distinct purchaser) as n_buyers
    , count (distinct seller) as n_sellers
    , count (distinct mint) as n_mints
    , sum(sales_amount) as volume
    , avg(sales_amount) as avg_price
    , median(sales_amount) as median_price
    , count(distinct block_timestamp::date) as n_days
    , sum(sales_amount * avg_price) as volume_usd
    from solana.nft.fact_nft_sales s
    join p
    on p.date = s.block_timestamp::date
    where block_timestamp::date < current_date
    and succeeded = 'TRUE'
    and sales_amount < 1000
    group by 1
    ), t1 as (
    select *
    , avg(volume) OVER (
    order by date
    rows between 29 preceding and current row
    ) AS rolling_avg_30_days
    QueryRunArchived: QueryRun has been archived