jackguy2023-05-01 07:09 PM copy
    Updated 2023-05-05
    -- forked from 2023-05-01 07:09 PM @ https://flipsidecrypto.xyz/edit/queries/9297a54a-1f32-46de-8a59-2cb16930ca4a

    SELECT
    CASE when volume_usd < 10 then 'a Below $10 Volume'
    when volume_usd < 100 then 'b $10 - $100 Volume'
    when volume_usd < 1000 then 'c $100 - $1,000 Volume'
    when volume_usd < 10000 then 'd $1,000 - $10,000 Volume'
    when volume_usd < 100000 then 'e $10,000 - $100,000 Volume'
    when volume_usd < 1000000 then 'f $100,000 - $1,000,000 Volume'
    else 'g $1,000,000+ Volume' end as user_group,
    count(*) as users

    FROM (
    SELECT --*,
    -- date_trunc('week', block_timestamp) as week,
    ORIGIN_FROM_ADDRESS,
    count(DISTINCT date_trunc('week', block_timestamp)) as active_weeks ,
    --count(DISTINCT ORIGIN_FROM_ADDRESS) as users,
    sum(
    CASE
    when not amount_in_usd is NULL then amount_in_usd
    when not amount_out_usd is NULL then amount_out_usd
    --when token_price1 is NULL then token_price2 * TOKEN_OUT
    --else token_price1 * TOKEN_IN end as tt
    else 0 end
    ) as volume_usd
    FROM avalanche.core.ez_dex_swaps
    LEFT outer join (
    SELECT
    date_trunc('day', hour) as day1,
    token_address as ta1,
    median(price) as token_price1
    FROM avalanche.core.fact_hourly_token_prices
    GROUP BY 1,2
    ) as a on day1 = date_trunc('day', block_timestamp)
    and ta1 = TOKEN_IN
    Run a query to Download Data