Query editor
WITH user_first_occurrence AS (SELECTproject,maker AS user_id,MIN(DATE_TRUNC('month', block_date)) AS first_occurrenceFROM dex.tradesWHEREproject = 'uniswap'--block_date > NOW() - INTERVAL '3' yearGROUP BY project, makerUNIONSELECTproject,taker AS user_id,MIN(DATE_TRUNC('month', block_date)) AS first_occurrenceFROM dex.tradesWHEREproject = 'uniswap'--block_date > NOW() - INTERVAL '2' yearGROUP BY project, taker)SELECTtime,'uniswap' as project,COUNT(CASE WHEN first_occurrence = time THEN 1 END) AS new_users,COUNT(CASE WHEN first_occurrence < time THEN 1 END) AS old_usersFROM (SELECTDATE_TRUNC('month', block_date) AS time,project,maker AS user_idFROM dex.tradesWHEREproject = 'uniswap'-- block_date > NOW() - INTERVAL '2' yearUNIONSELECTDATE_TRUNC('month', block_date) AS time,project,taker AS user_idFROM dex.tradesWHEREproject = 'uniswap'-- block_date > NOW() - INTERVAL '2' year) AS tradersJOIN user_first_occurrence ON traders.project = user_first_occurrence.project AND traders.user_id = user_first_occurrence.user_idGROUP BY 1, 2ORDER BY 1;