binhachon18. [Easy] Wealth distribution - Base table - Detail for top 5%
    Updated 2021-11-07
    with wealth_distribution as(
    select address, sum(amount) as balance from (
    select from_address as address, -rune_amount as amount from thorchain.transfers
    union all
    select to_address as address, rune_amount as amount from thorchain.transfers
    )
    group by address
    ),
    percentile as(
    select '1' as symbol, percentile_cont(0.25) within group (order by balance) as percentile_25,
    percentile_cont(0.5) within group (order by balance) as percentile_50,
    percentile_cont(0.75) within group (order by balance) as percentile_75,
    percentile_cont(0.80) within group (order by balance) as percentile_80,
    percentile_cont(0.85) within group (order by balance) as percentile_85,
    percentile_cont(0.90) within group (order by balance) as percentile_90,
    percentile_cont(0.95) within group (order by balance) as percentile_95
    from wealth_distribution
    where balance > 0
    group by symbol
    )
    select address, balance
    from wealth_distribution, percentile
    where balance >= percentile_95
    order by balance desc


    Run a query to Download Data