Query editor
with dws as (select evt_block_time as block_time, "from" as user,l1Token as token_address, cast(amount as double) as raw_amount,'deposit' as tx_typefrom zksync_v2_ethereum.L1ERC20Bridge_evt_DepositInitiatedunionselect evt_block_time as block_time, "to" as user,l1Token as token_address, cast(amount as double) * -1 as raw_amount,'withdraw' as tx_typefrom zksync_v2_ethereum.L1ERC20Bridge_evt_WithdrawalFinalizedunionselect block_time, bytearray_substring(data, 205, 20) as user,0x0000000000000000000000000000000000000000 as token_address,cast(bytearray_to_uint256(bytearray_substring(data, 449, 32)) as double) as raw_amount,'deposit' as tx_typefrom ethereum.logswhere block_time >= timestamp '2023-2-14 10:11'and contract_address = 0x32400084c286cf3e17e7b677ea9583e60a000324and topic0 = 0x4531cd5795773d7101c17bdeb9f5ab7f47d7056017506f937083be5d6e77a382unionselect evt_block_time as block_time, to as user,0x0000000000000000000000000000000000000000 as token_address,cast(amount as double) * -1 as raw_amount,'withdraw' as tx_typefrom zksync_ethereum.MailboxFacet_evt_EthWithdrawalFinalized), tmp1 as (select user, token_address,count(distinct token_address) as tokens_deposited,sum(if(tx_type = 'deposit', 1, 0)) as deposits,sum(if(tx_type = 'withdraw', 1, 0)) as withdraws,sum(if(tx_type = 'deposit', raw_amount, 0)) as deposit_raw_amount,sum(if(tx_type = 'withdraw', raw_amount, 0)) as withdraw_raw_amount,sum(raw_amount) as total_raw_amountfrom dwsgroup by 1,2),tmp2 as (select user, sum(tokens_deposited) as tokens_deposited,sum(deposits) as deposits, sum(withdraws) as withdrawsfrom tmp1group by 1),tmp3 as ((select 1 as "rank", '1' as deposits, sum(if(deposits = 1, 1, 0)) as usersfrom tmp2unionselect 2 as "rank", '2 - 3' as deposits, sum(if(deposits >= 2 and deposits <= 3, 1, 0)) as usersfrom tmp2unionselect 3 as "rank", '4 - 5' as deposits, sum(if(deposits >= 4 and deposits <= 5, 1, 0)) as usersfrom tmp2unionselect 4 as "rank", '6 - 10' as deposits, sum(if(deposits >= 6 and deposits <= 10, 1, 0)) as usersfrom tmp2unionselect 5 as "rank", '11 - 20' as deposits, sum(if(deposits >= 11 and deposits <= 20, 1, 0)) as usersfrom tmp2unionselect 6 as "rank", '> 20' as deposits, sum(if(deposits > 20, 1, 0)) as users