Moe8 Race
    Updated 2022-10-23
    with base as (select
    distinct BUYER

    from flow.core.fact_nft_sales
    where 1=1
    and NFT_COLLECTION ilike 'A.329feb3ab062d289.RaceDay_NFT'
    and TX_SUCCEEDED = 'TRUE'
    ),
    flow_prices as (
    select date_trunc('day', timestamp)::Date as day,
    avg(price_usd) as flow_price
    from flow.core.fact_prices
    group by 1),


    final as (select
    s.*,
    case
    when currency = 'A.1654653399040a61.FlowToken' then price*flow_price else price end as price_usd
    from flow.core.fact_nft_sales s,flow_prices p
    where tx_succeeded = 'TRUE'
    and s.BLOCK_TIMESTAMP::date = p.day
    ),
    buying as (select
    BLOCK_TIMESTAMP as buy_date,buyer,
    NFT_COLLECTION as buy_collection,NFT_ID b_NFT_ID,price_usd as buy_usd
    from final
    where 1=1
    and buyer in (select buyer from base)
    and TX_SUCCEEDED = 'TRUE'
    ),

    selling as (select
    Run a query to Download Data