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 = 0x0C03Ce270B4826Ec62e7DD007f0B716068639F7BUNION ALLSELECTDATE_TRUNC('day', evt_block_time) AS time,"from" as wallet,-cast(value as DOUBLE) AS amtFROM erc20_base.evt_TransferWHERE contract_address = 0x0C03Ce270B4826Ec62e7DD007f0B716068639F7B),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 >= 100000) AS "Whales 100k+",COUNT(wallet) FILTER (WHERE cur_bal < 100000 and cur_bal>=10000) AS "Sharks <100k",COUNT(wallet) FILTER (WHERE cur_bal< 10000 and cur_bal>= 1000) AS "Dolphins <10k",COUNT(wallet) FILTER (WHERE cur_bal < 1000 and cur_bal >= 100) AS "Fish <1k"from wallet_balancegroup by 1order by time desc