Ali3NDistribution of UNI SNX MKR Borrowers By Their Borrows Volume AAVE v2
    Updated 2023-03-08
    with maintable as (
    select borrower_address,
    symbol,
    count (Distinct tx_hash) as Borrows_Count,
    sum (borrowed_usd) as Total_Borrowed_USD,
    avg (borrowed_usd) as Average_Borrowed_USD,
    median (borrowed_Usd) as Median_Borrowed_USD,
    min (borrowed_Usd) as Minimum_Borrowed_USD,
    max (borrowed_Usd) as Maximum_Borrowed_USD,
    sum (borrowed_tokens) as Total_Borrowed_Token,
    avg (borrowed_tokens) as Average_Borrowed_Token
    from ethereum.aave.ez_borrows
    where aave_version = 'Aave V2'
    and symbol in ('SNX','UNI','MKR')
    and borrowed_usd > 0
    group by 1,2)

    select symbol,
    case when total_borrowed_usd < 10 then 'Less Than $10'
    when total_borrowed_usd >= 10 and total_borrowed_usd < 100 then '$10 - $100'
    when total_borrowed_usd >= 100 and total_borrowed_usd < 1000 then '$100 - $1,000'
    when total_borrowed_usd >= 1000 and total_borrowed_usd < 10000 then '$1,000 - $10,000'
    when total_borrowed_usd >= 10000 and total_borrowed_usd < 100000 then '$10,000 - $100,000'
    else 'More Than $100,000' end as type,
    count (Distinct borrower_address)
    from maintable
    group by 1,2
    order by 3 desc


    Run a query to Download Data