with whales as(select
address,
sum (balance) as total_luna_balance,
sum (balance_usd) as total_usd_balance,
row_number() over (order by total_luna_balance desc) as row_number
from terra.classic.dim_daily_balances
where currency = 'LUNA'
and date = (select max(date) from terra.classic.dim_daily_balances)
group by 1
having (total_usd_balance >= 1000000)
)
select date,
sum (balance) as total_luna_balance,
sum (balance_usd) as total_usd_balance
from terra.classic.dim_daily_balances
where currency = 'LUNA'
and address in (select address from whales)
and date >= '2022-05-01'
group by 1
order by 1