Sbhn_NPDaily volume sales buyers average price by chains
    Updated 2022-09-17
    --inspired by cristinatinto
    with
    flow_price as (
    SELECT
    date_trunc('day',timestamp) as days,
    avg(price_usd) as flow_price
    from flow.core.fact_prices
    group by 1
    ),
    t1 as (
    SELECT
    block_timestamp,
    tx_id,
    buyer,
    case when currency like '%Flow%' then price*flow_price
    else price end as price
    from flow.core.ez_nft_sales x
    join flow_price y on date_trunc('day',x.block_timestamp)=y.days
    ),
    t12 as (
    select
    date_trunc('day',block_timestamp) as days,
    'Flow' as chain,
    count(distinct buyer) as buyers,
    count(DISTINCT tx_id) as sales,
    sum(price) as volume,
    avg(price) as avg_price
    from flow.core.ez_nft_sales
    where block_timestamp >= '2022-01-01'
    and price != 0
    and tx_succeeded = TRUE
    group by 1,2
    ),
    t2 as (
    select
    date_trunc('day',block_timestamp) as days,
    Run a query to Download Data