Query editor
WITHaddresses AS (SELECT"to" AS adrFROMerc20_ethereum.evt_Transfer AS trWHEREcontract_address = 0xb31eF9e52d94D4120eb44Fe1ddfDe5B4654A6515),transfers AS (SELECTday,address,token_address,SUM(amount) AS amountFROM(SELECTDATE_TRUNC('day', evt_block_time) AS day,"to" AS address,tr.contract_address AS token_address,value AS amountFROMerc20_ethereum.evt_Transfer AS trWHEREcontract_address = 0xb31eF9e52d94D4120eb44Fe1ddfDe5B4654A6515UNION ALLSELECTDATE_TRUNC('day', evt_block_time) AS day,"from" AS address,tr.contract_address AS token_address,value AS amountFROMerc20_ethereum.evt_Transfer AS trWHEREcontract_address = 0xb31eF9e52d94D4120eb44Fe1ddfDe5B4654A6515) AS tGROUP BY1,2,3),balances_with_gap_days AS (SELECTt.day,address,SUM(amount) OVER (PARTITION BYaddressORDER BYt.day) AS balance,/* balance per day with a transfer */ LEAD(day, 1, CURRENT_TIMESTAMP) OVER (PARTITION BYaddressORDER BYt.day) AS next_day /* the day after a day with a transfer */FROMtransfers AS t