Query editor
WITHeth_price AS (SELECTdate_trunc('hour', minute) AS day,AVG(price) AS avg_eth_priceFROMprices.usdWHEREblockchain = 'ethereum'AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2AND minute >= date('2023-08-10')GROUP BY1),trades AS (SELECT*FROMcoordinape_optimism.CoLinks_evt_LinkTx),firstUserOccurrences AS (SELECTholder,MIN(trades.evt_block_time) AS firstTradeDateFROMtradesGROUP BY1),statsByDay AS (SELECTdate_trunc('day', evt_block_time) as evt_block_time,-- evt_block_time,-- SUM(volumeUSD) AS volumeUSD,SUM(ethAmount + protocolEthAmount + targetEthAmount)/1e18 AS volumeETH,COUNT(DISTINCT (trades.holder)) AS numberOfTraders,COALESCE(COUNT(DISTINCT (firstUserOccurrences.holder)), 0) AS numberOfNewTraders,COUNT(DISTINCT (trades.holder)) - COALESCE(COUNT(DISTINCT (firstUserOccurrences.holder)), 0) AS numberOfReturningTraders,-- SUM(feeUSD) AS feesUSD,SUM(protocolEthAmount/1e18) AS protocolFeesETH,SUM(targetEthAmount/1e18) AS targetFeesETH,-- SUM(referralEthAmount/1e18) AS referralFeesETH,-- SUM(IF(type = 'Buy', volumeUSD, NULL)) AS buyVolumeUSD,SUM(CASE WHEN isBuy = True THEN ethAmount ELSE NULL END) / 1e18 as buyVolumeETH,-- SUM(IF(type = 'Sell', volumeUSD, NULL)) AS sellvolumeUSD,SUM(CASE WHEN isBuy = True THEN NULL ELSE ethAmount END) / 1e18 as sellVolumeETH,COUNT(DISTINCT (evt_tx_hash)) AS numberOfTrades,SUM(linkAmount) AS numberOfPassesTraded-- SUM(-- COALESCE(COUNT(DISTINCT (firstUserOccurrences.trader)), 0)-- ) OVER (-- ORDER BY-- evt_block_time-- ) AS cumulative_numberOfNewTradersFROMtradesLEFT OUTER JOIN firstUserOccurrences ON (trades.holder = firstUserOccurrences.holderAND trades.evt_block_time = firstUserOccurrences.firstTradeDate)