Query editor
WITH listed AS (SELECT listingId, collection, CAST(value AS double) / 1e18 AS backing, evt_block_date AS dFROM token_works_ethereum.fwa_evt_nftlisted),moves AS (SELECT d, collection, 1 AS dl, backing AS db FROM listedUNION ALLSELECT a.evt_block_date, l.collection, -1, -l.backingFROM token_works_ethereum.fwa_evt_nftallocated aJOIN listed l ON a.listingId = l.listingIdUNION ALLSELECT w.evt_block_date, l.collection, -1, -l.backingFROM token_works_ethereum.fwa_evt_listingwithdrawn wJOIN listed l ON w.listingId = l.listingId),daily AS (SELECT d, collection, SUM(dl) AS net_l, SUM(db) AS net_bFROM moves GROUP BY 1, 2),grid AS (SELECT dd.d, cc.collectionFROM (SELECT DISTINCT d FROM daily) ddCROSS JOIN (SELECT DISTINCT collection FROM daily) cc),filled AS (SELECT g.d, g.collection, COALESCE(x.net_l, 0) AS net_l, COALESCE(x.net_b, 0) AS net_bFROM grid g LEFT JOIN daily x ON g.d = x.d AND g.collection = x.collection),running AS (SELECT d, collection,SUM(net_l) OVER (PARTITION BY collection ORDER BY d) AS active_listings,SUM(net_b) OVER (PARTITION BY collection ORDER BY d) AS active_backing_ethFROM filled)SELECT r.d AS day,COALESCE(c.collection_name, CONCAT('0x', TO_HEX(r.collection))) AS collection_name,r.active_listings,r.active_backing_ethFROM running rLEFT JOIN query_8175901 c ON r.collection = c.collectionWHERE r.active_listings > 0ORDER BY 1, 3 DESC