Query editor
WITHtransfers AS (SELECTt."from" AS from_addr,t."to" AS to_addr,t.value / POW(10, tok.decimals) AS amount,t.evt_block_timeFROM erc20_ethereum.evt_transfer tJOIN tokens.erc20 tokON t.contract_address = tok.contract_addressWHERE t.contract_address = 0x57e114b691db790c35207b2e685d4a43181e6061),period_window AS (SELECTDATE_TRUNC('day', NOW() - INTERVAL '30' DAY) AS period_start,NOW() AS period_end),holder_balance AS (SELECTwallet,SUM(flow) AS balanceFROM (SELECT to_addr AS wallet, amount AS flow FROM transfersUNION ALLSELECT from_addr AS wallet, -amount AS flow FROM transfers)GROUP BY wallet),non_cex_holders AS (SELECTwallet,balanceFROM holder_balanceWHERE balance > 0AND wallet NOT IN (SELECT address FROM labels.cex)),top_20_holders AS (SELECTwallet,balanceFROM non_cex_holdersORDER BY balance DESCLIMIT 20),inflows_30d AS (SELECTt.evt_block_time,t.to_addr AS wallet,t.amount AS in_flow,0 AS out_flowFROM transfers tCROSS JOIN period_window pWHERE t.evt_block_time BETWEEN p.period_start AND p.period_end