Query editor
with deposits as (selectt."from" as wallet, min(d.call_block_time) as deposit_time, sum(d."_depositAmount" / 10^18) as amtfrom alchemix."StakingPools_call_deposit" djoin erc20."ERC20_evt_Transfer" ton t.evt_tx_hash = d.call_tx_hashgroup by 1), withdrawals as (selectt."to" as wallet, min(e.call_block_time) as exit_timefrom alchemix."StakingPools_call_exit" ejoin erc20."ERC20_evt_Transfer" ton t.evt_tx_hash = e.call_tx_hashgroup by 1), combined as (selectd.wallet--, amt, d.deposit_time, w.exit_time, case when exit_time isnull then 'still staked' else 'exited' end as staked_status, case when exit_time isnull then date_part('day', current_date - deposit_time) end as days_staked_so_far, exit_time - deposit_time as time_staked, date_part('day', exit_time - deposit_time) as days_stakedfrom deposits dleft join withdrawals won d.wallet = w.wallet), days_staked_summary as (selectcoalesce(days_staked, days_staked_so_far) as days_staked, count(wallet) as wallets--, sum(amt) as amtfrom combinedgroup by 1order by 1), total as (select sum(wallets) as total_wallets from days_staked_summary)selectcasewhen days_staked <= 5 then '0-5'when days_staked <= 10 then '06-10'when days_staked <= 15 then '11-15'when days_staked <= 20 then '16-20'when days_staked <= 25 then '21-25'when days_staked <= 30 then '26-30'when days_staked > 30 then '>30'