Updated 2022-08-03
    with balance_left as(

    select
    a.BLOCK_TIMESTAMP::date as date,
    INSTRUCTION:accounts as users,
    sum(inner_instruction:instructions[1]:parsed:info:amount)/1e6 as borrowed_volume
    from solana.core.fact_events a
    where
    instruction:programId = 'So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo'
    and instruction:accounts[0] = '8SheGtsopRUDzdiD6v6BR9a6bqZ9QwywYQY99Fp5meNf'
    and instruction:accounts[2] = 'BgxfHJDzm44T7XG68MYKx7YisTjZu73tVovyZSjJMpmw'
    and succeeded = 'TRUE'
    and date >= '2022-01-01'
    group by 1,2
    order by 3
    ),
    data_1 as (
    select
    date,
    users,
    (borrowed_volume) as total_usd_borrow
    from balance_left
    )

    SELECT
    date,
    CASE
    WHEN total_usd_borrow <100 then 'Under 100 USDC Borrowed'
    WHEN total_usd_borrow >=100 and total_usd_borrow <5000 then 'between 100 USDC and 1000 USDC Borrowed'
    WHEN total_usd_borrow >=5000 and total_usd_borrow <10000 then 'between 5000 USDC and 10000 USDC Borrowed'
    WHEN total_usd_borrow >=10000 and total_usd_borrow <100000 then 'between 10000 USDC and 100000 USDC Borrowed'
    WHEN total_usd_borrow >=100000 and total_usd_borrow <1000000 then 'between 100000 USDC and 1000000 USDC Borrowed'
    WHEN total_usd_borrow >=1000000 then 'Above 1 million USDC Borrowed'
    end as distribution,
    count(distribution)
    from data_1
    Run a query to Download Data