Query editor
with gs as (with days_seq as (SELECTsequence((SELECT cast(min(date_trunc('day', evt_block_time)) as timestamp) time FROM erc20_ethereum.evt_Transfer tr), date_trunc('day', cast(now() as timestamp)), interval '1' day) as time)SELECTgs.timeFROM days_seqCROSS JOIN unnest(time) as gs(time) --this is just doing explode like in spark sql),tx AS (SELECTDATE_TRUNC('day', evt_block_time) AS time,"to" as wallet,cast(value as DOUBLE) AS amtFROM erc20_base.evt_TransferWHERE contract_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4UNION ALLSELECTDATE_TRUNC('day', evt_block_time) AS time,"from" as wallet,-cast(value as DOUBLE) AS amtFROM erc20_base.evt_TransferWHERE contract_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4),wallet_balance AS (WITH balance_with_gap AS (SELECTtime,LEAD(time, 1, DATE_TRUNC ('day', NOW())) OVER (PARTITION BY wallet ORDER BY time) AS next_time,wallet,SUM(SUM(amt)/power(10,18)) OVER (PARTITION BY wallet ORDER BY time) AS cur_balFROM txGROUP BY 1,3)SELECTgs.time,wallet,cur_balFROM balance_with_gap hINNER JOIN gs ON h.time <= gs.time AND gs.time < h.next_time)select time,COUNT(wallet) AS holders,COUNT(wallet) FILTER (WHERE cur_bal >= 100000000) AS "Whales",COUNT(wallet) FILTER (WHERE cur_bal < 100000000 and cur_bal>=10000000) AS "Sharks",COUNT(wallet) FILTER (WHERE cur_bal< 10000000 and cur_bal>= 1000000) AS "Dolphins",COUNT(wallet) FILTER (WHERE cur_bal < 1000000 and cur_bal >= 50000) AS "Fish"from wallet_balancegroup by 1order by time desc