Query editor
WITH sup AS (SELECT chain, contract_address, evt_tx_hash, evt_index, reserve FROM aave_v3_multichain.pool_evt_supplyWHERE evt_block_time >= TIMESTAMP '2022-03-01' AND evt_block_time < TIMESTAMP '2023-09-08'),wd AS (SELECT chain, contract_address, evt_tx_hash, evt_index, reserve FROM aave_v3_multichain.pool_evt_withdrawWHERE evt_block_time >= TIMESTAMP '2022-03-01' AND evt_block_time < TIMESTAMP '2023-09-08'),rdu AS (SELECT chain, contract_address, evt_tx_hash, evt_index, reserve FROM aave_v3_multichain.pool_evt_reservedataupdatedWHERE evt_block_time >= TIMESTAMP '2022-03-01' AND evt_block_time < TIMESTAMP '2023-09-08')SELECT 'supply' AS tbl, chain, COUNT(*) AS n_rows, COUNT(DISTINCT ROW(evt_tx_hash, evt_index)) AS n_distinct,COUNT(DISTINCT contract_address) AS n_contracts,SUM(CASE WHEN EXISTS (SELECT 1 FROM rdu r WHERE r.chain = s.chain AND r.evt_tx_hash = s.evt_tx_hash AND r.reserve = s.reserve AND r.evt_index < s.evt_index) THEN 1 ELSE 0 END) AS n_with_rdu_beforeFROM sup s GROUP BY chainUNION ALLSELECT 'withdraw', chain, COUNT(*), COUNT(DISTINCT ROW(evt_tx_hash, evt_index)), COUNT(DISTINCT contract_address),SUM(CASE WHEN EXISTS (SELECT 1 FROM rdu r WHERE r.chain = w.chain AND r.evt_tx_hash = w.evt_tx_hash AND r.reserve = w.reserve AND r.evt_index < w.evt_index) THEN 1 ELSE 0 END)FROM wd w GROUP BY chainUNION ALLSELECT 'rdu', chain, COUNT(*), COUNT(DISTINCT ROW(evt_tx_hash, evt_index)), COUNT(DISTINCT contract_address), NULLFROM rdu GROUP BY chainORDER BY 1, 2