Updated 2022-10-19
    with tab1 as (
    SELECT TIMESTAMP::date as daily , avg(price_usd) as price ,
    case
    when daily >=CURRENT_DATE - 90 then 'Last 90 days'
    else 'Earlier' end as type
    from near.core.fact_prices
    where SYMBOL ilike '%NEAR%'
    group by 1 , 3
    )
    , tab2 as (
    SELECT block_TIMESTAMP::date as daily , SUM(case when ACTION = 'Stake' then STAKE_AMOUNT
    when action = 'Unstake' then -STAKE_AMOUNT end )*power(10,-24) as net_staked ,
    case
    when block_timestamp::date >=CURRENT_DATE -90 then 'Last 90 days'
    else 'Earlier' end as type
    from near.core.dim_staking_actions
    GROUP by 1 , 3
    )
    SELECT A.daily , B.type , net_staked , price
    from tab1 A , tab2 B
    where A.daily = B.daily
    and A.type = B.type

    Run a query to Download Data