Query editor
WITH transfers AS (SELECTbytearray_to_uint256(topic3) AS token_id,bytearray_substring(topic2, 13, 20) AS to_addr,CAST(block_time AS timestamp) AS block_ts,block_number * 1000000 + "index" AS sort_keyFROM ethereum.logsWHERE contract_address = 0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13dAND topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef),snapshots AS (SELECT CAST(d AS timestamp) AS snap_dateFROM UNNEST(SEQUENCE(date_add('month', -36, date_trunc('month', current_date)),date_trunc('month', current_date),INTERVAL '1' MONTH)) AS t(d)UNION ALLSELECT CAST(NOW() AS timestamp) AS snap_date),ownership AS (SELECTs.snap_date,t.token_id,MAX_BY(t.to_addr, t.sort_key) AS ownerFROM snapshots sJOIN transfers tON t.block_ts <= s.snap_dateGROUP BY 1, 2)SELECTsnap_date,COUNT(DISTINCT owner) AS distinct_holders,COUNT(token_id) AS apes_in_walletsFROM ownershipWHERE owner NOT IN (0x000000000000000000000000000000000000dead,0x0000000000000000000000000000000000000000)GROUP BY 1ORDER BY 1