select
*,
luna_staked - luna_unstaked as net_luna_staked
from (select
dateadd(day, 21, date(block_timestamp)) as block_date,
sum(event_amount) as luna_unstaked
from terra.staking
where action = 'undelegate'
and block_date > date('2021-08-01')
and tx_status = 'SUCCEEDED'
group by 1) a
inner join
(select
dateadd(day, 21, date(block_timestamp)) as block_date,
sum(event_amount) as luna_staked
from terra.staking
where action = 'delegate'
and block_date > date('2021-08-01')
and tx_status = 'SUCCEEDED'
group by 1) b
on a.block_date = b.block_date