Updated 2022-12-07
    -- this code is thankfully burrowed from 0xHaM☰d: https://app.flipsidecrypto.com/dashboard/5hamvc
    with pricTb as (
    select
    timestamp::date as p_date,
    avg(price_usd) as usdprice
    from flow.core.fact_prices
    where symbol = 'FLOW'
    and source = 'coinmarketcap'
    group by 1
    )
    , laligaTb as (
    select
    BLOCK_TIMESTAMP::date as date,
    row_number () over (order by date) as day_rank,
    'LaLiga Golazos' as collection,
    COUNT(DISTINCT tx_id) as sales_cnt,
    COUNT(DISTINCT buyer) as buyer_cnt,
    COUNT(DISTINCT seller) as seller_cnt,
    COUNT(DISTINCT nft_id) as nft_cnt,
    sum(case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as volume,
    avg(case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as avg_price,
    max(case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as max_price,
    min(case when currency = 'A.1654653399040a61.FlowToken' then price*usdprice else price end) as floor_price,
    sum(sales_cnt) over (order by date) as cum_sales_cnt,
    sum(volume) over (order by date) as cum_volume
    from flow.core.ez_nft_sales s join pricTb p on s.block_timestamp::Date = p.p_date
    where nft_collection in ('A.87ca73a41bb50ad5.Golazos')
    and tx_succeeded = 'TRUE'
    GROUP by 1,3
    ORDER by 1 ASC
    limit 30
    )
    , TopShotTb as (
    select
    BLOCK_TIMESTAMP::date as date,
    row_number () over (order by date) as day_rank,
    Run a query to Download Data