Afonso_Diaz2023-08-13 12:58 AM
    Updated 2023-08-12
    with t1 as (
    select date(block_timestamp) as date,
    token_in ,
    (sum(amount_out)/sum(amount_in)) as price
    from near.core.ez_dex_swaps
    where token_out = 'wNEAR'
    and amount_out > 0 and amount_in > 0
    and date >= current_date - 14
    and token_in ilike '%sweat%'
    group by 1, 2
    ),

    t2 as (
    select timestamp::date as date,
    'Near' as symbol,
    avg(price_usd) as near_price_usd
    from near.core.fact_prices
    where token = 'LiNEAR'
    and timestamp >= current_date - 14
    group by 1, 2
    ),

    t3 as (
    select
    t2.date,
    price * near_price_usd as sweat_price_usd
    from t2 left join t1
    using(date)
    )

    select
    t2.date,
    sweat_price_usd,
    near_price_usd
    from t2
    left join t3
    Run a query to Download Data