Query editor
WITH user_balance AS (SELECT date,address,SUM(SUM(amount)) OVER (PARTITION BY address ORDER BY date) as daily_cumulative_balance -- get the cumulative balance of the holdersFROM (SELECT date_trunc('day',evt_block_time) as date,tr."from" AS address,-(tr.value/1e18) AS amountFROM erc20_fantom.evt_transfer trWHERE "from" != 0x0000000000000000000000000000000000000000 -- exclude mint/burn addressesAND contract_address = 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 -- contract_address of the erc20 tokenUNION ALLSELECT date_trunc('day',evt_block_time) as date,tr."to" AS address,(tr.value/1e18) AS amountFROM erc20_fantom.evt_transfer trWHERE "to" != 0x0000000000000000000000000000000000000000 -- exclude mint/burn addressesAND contract_address = 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 -- contract_address of the erc20 token) xGROUP BY 1,2),setLeadData as (SELECT *,lead(date,1,NOW()) OVER (PARTITION BY address ORDER BY date) as latest_day FROM user_balance),gs as (SELECT date FROM UNNEST(sequence(CAST('2023-06-28' AS TIMESTAMP),CAST(NOW() AS TIMESTAMP),interval '1' day)) as tbl(date)),getUserDailyBalance as (SELECT gs.date,address,daily_cumulative_balanceFROM setLeadData gINNER JOIN gs ON g.date <= gs.date AND gs.date < g.latest_dayWHERE daily_cumulative_balance > 1/1e12)SELECT date,COUNT(address) as holders,COUNT(address) - LAG(COUNT(address)) OVER (ORDER BY date) as changeFROM getUserDailyBalanceGROUP BY 1ORDER BY 1 DESC