Query editor
with timeframe as (selectcase when '{{Staking Timeframe}}' = 'monthly' then date('2023-04-12')when '{{Staking Timeframe}}' = 'weekly' then now() - interval '1' yearwhen '{{Staking Timeframe}}' = 'daily' then now() - interval '3' monthwhen '{{Staking Timeframe}}' = 'hourly' then now() - interval '7' dayend as start_date,case when '{{Staking Timeframe}}' = 'monthly' then 'month'when '{{Staking Timeframe}}' = 'weekly' then 'week'when '{{Staking Timeframe}}' = 'daily' then 'day'when '{{Staking Timeframe}}' = 'hourly' then 'hour'end as interval),entities as (select depositor_address as address, entity, categoryfrom staking_ethereum.entities),deposit as (select date_trunc((select interval from timeframe),block_time) as time, "from" as address, sum(cast(value as double))/1e18 as staked_ethFROM ethereum.tracesWHERE "to" in (0x00000000219ab540356cBB839Cbe05303d7705Fa,0x3f124c700fb5e741f128e28985267d44f56b242f)AND "from" <> 0x3f124c700fb5e741f128e28985267d44f56b242fAND (LOWER(call_type) NOT IN ('delegatecall', 'callcode', 'staticcall') or call_type is null)AND successAND cast(value as double) > 0AND block_time >= (select start_date from timeframe)group by 1,2),deposit_entity as (select distinct time,case when entity is null then 'Others' else entity end as entity,sum(staked_eth) as staked_eth from deposit aleft join entities bon a.address=b.addressgroup by 1,2)select time, case when ranking>10 then 'Others' else entity end as entity,sum(staked_eth) as staked_ethfrom (select rank() over (partition by time order by staked_eth desc) as ranking, * from deposit_entity)agroup by 1,2