ramishoowUntitled Query
    Updated 2022-12-15
    with ramishow as(select date_trunc('day',RECORDED_HOUR) as time, avg(CLOSE) as price from crosschain.core.fact_hourly_prices
    where ID = 'terra-luna-2' group by 1 ),main as (select date_trunc('day',block_timestamp) as time,
    RECEIVER, TX_ID, sum(AMOUNT)/pow(10,6) as "staking reward (Luna)" from terra.core.ez_transfers where MESSAGE_VALUE['@type'] ='/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward'
    and CURRENCY='uluna' and TX_SUCCEEDED = TRUE group by 1,2,3 ), main1 as(select DISTINCT RECEIVER as user, count(DISTINCT tx_id) as "count of rewards distributed",
    sum("staking reward (Luna)"*price) as "total staking reward (USD)" from main s join ramishow x on s.time=x.time group by 1) select case when "count of rewards distributed" = 1 then 'just once rewarded'
    when "total staking reward (USD)" < 100 then 'less than 100 USD'
    when "total staking reward (USD)" between 100 and 499.99 then '100 - 500 USD'
    --when "total staking reward (USD)" between 10000 and 2499.99 then '1 K - 2.5 K USD'
    when "total staking reward (USD)" between 500 and 999.99 then '500 - 1 K USD'
    when "total staking reward (USD)" between 10000 and 2499.99 then '1 K - 2.5 K USD'
    when "total staking reward (USD)" between 2500 and 4999.99 then '2.5 K - 5 K USD'
    when "total staking reward (USD)" between 5000 and 9999.99 then '5 K - 10 K USD'
    when "total staking reward (USD)" between 10000 and 19999.99 then '10 K - 20 K USD'
    when "total staking reward (USD)" between 20000 and 49999.99 then '20 K - 50 K USD'
    when "total staking reward (USD)" between 50000 and 999999.99 then '50 K - 100 K USD'
    else 'more than 100 K USD'
    end as "staking reward volume",
    count(user) as "count of users" from main1 group by 1