with delegate as (select VALIDATOR_ADDRESS, sum(amount/pow(10,6)) as delegate
from osmosis.core.fact_staking
where TX_STATUS = 'SUCCEEDED'
and action = 'delegate'
and currency = 'uosmo'
group by 1
order by 2),
undelegate as (select VALIDATOR_ADDRESS, sum(amount/pow(10,6)) as undelegate
from osmosis.core.fact_staking
where TX_STATUS = 'SUCCEEDED'
and action = 'undelegate'
and currency = 'uosmo'
group by 1
order by 2)
select d.VALIDATOR_ADDRESS, sum(delegate - undelegate) as total, rank() over (ORDER by total desc) as rank
from delegate d
join undelegate u
on d.VALIDATOR_ADDRESS = u.VALIDATOR_ADDRESS
group by 1
order by 2 desc
limit 10