Query editor
with stake as (select *,coalesce(cast(json_extract(data, '$.add_stake_fee') as bigint) / 1e8, 0) as add_stake_fee,coalesce(cast(json_extract(data, '$.amount_added') as bigint) / 1e8, 0) as amount,cast(json_extract(data, '$.delegator_address') as varchar) as delegator_address,cast(json_extract(data, '$.pool_address') as varchar) as pool_address,'addstake' as evt_typefrom aptos.eventswhere event_type like '%delegation_pool::AddStakeEvent%'),unstake as (select *,coalesce(cast(json_extract(data, '$.add_stake_fee') as bigint) / 1e8, 0) as add_stake_fee,coalesce(cast(json_extract(data, '$.amount_unlocked') as bigint) / 1e8, 0) as amount,cast(json_extract(data, '$.delegator_address') as varchar) as delegator_address,cast(json_extract(data, '$.pool_address') as varchar) as pool_address,'unlockstake' as evt_typefrom aptos.eventswhere event_type like '%delegation_pool::UnlockStakeEvent%'),reactivatestake as (select *,coalesce(cast(json_extract(data, '$.add_stake_fee') as bigint) / 1e8, 0) as add_stake_fee,coalesce(cast(json_extract(data, '$.amount_reactivated') as bigint) / 1e8, 0) as amount,cast(json_extract(data, '$.delegator_address') as varchar) as delegator_address,cast(json_extract(data, '$.pool_address') as varchar) as pool_address,'reactivatestake' as evt_typefrom aptos.eventswhere event_type like '%delegation_pool::ReactivateStakeEvent%'),combined as (select * from stakeunion allselect * from unstakeunion allselect * from reactivatestake),moa_pool as (selectblock_date,'moa' as operator,sum(case when evt_type = 'addstake' then amount else 0 end) as AddStake_Amount,(sum(case when evt_type = 'unlockstake' then amount else 0 end) - sum(case when evt_type = 'reactivatestake' then amount else 0 end)) as UnlockStake_Amount,sum(case when evt_type = 'addstake' then amount else 0 end) - (sum(case when evt_type = 'unlockstake' then amount else 0 end) - sum(case when evt_type = 'reactivatestake' then amount else 0 end)) as Stake_Amount-- case when sum(case when evt_type = 'addstake' then amount else 0 end) < (sum(case when evt_type = 'unlockstake' then amount else 0 end) - sum(case when evt_type = 'reactivatestake' then amount else 0 end))-- then sum(case when evt_type = 'addstake' then amount else 0 end)-- else sum(case when evt_type = 'addstake' then amount else 0 end) - (sum(case when evt_type = 'unlockstake' then amount else 0 end) - sum(case when evt_type = 'reactivatestake' then amount else 0 end))-- end as Stake_Amount--(sum(case when evt_type = 'addstake' then amount else 0 end) - (sum(case when evt_type = 'unlockstake' then amount else 0 end) - sum(case when evt_type = 'reactivatestake' then amount else 0 end))) as Stake_Amountfrom combinedwhere tx_success = trueand pool_address = '0xe2789cdac410113f017fa684bf08fbacd0877612d84464ae6e8474b56e5f21da'group by 1,2)select *,