with voters as (select voter as v, count(*) as c from osmosis.core.fact_governance_votes where proposal_id=362
group by v
)
, voters_histogram as (select count(*) as cc , c from voters
group by c)
, voters_more_than_once_vote as (select voter, count(distinct vote_option) as vp from osmosis.core.fact_governance_votes
where voter in (select v from voters where c>1)
group by voter)
,voters_more_than_once_vote_histogram as (select count(*) as cvp ,vp from voters_more_than_once_vote
group by vp)
, OSMO_balance as (select sum(BALANCE/1e6) as bal , address from osmosis.core.fact_daily_balances
where CURRENCY = 'uosmo' and DATE= (select max(ds.DATE)
from osmosis.core.fact_daily_balances as ds inner join osmosis.core.fact_governance_votes
on address=voter and PROPOSAL_ID=365
) and address in (select v from voters)
group by address)
select address,avg(bal) from OSMO_balance
where address in (select voter from voters_more_than_once_vote where vp>1)
group by address
order by 2 desc
limit 20