Query editor
WITH-- create sub-query called 'tokens' containing token address and the timestamp of the minttokens AS (SELECTtoken_mint_address,MIN(block_time) AS token_birth_dateFROMtokens_solana.transfersWHEREaction = 'mint'GROUP BYtoken_mint_address),-- calculates the token supply for each tokentoken_supply AS (SELECTtoken_mint_address,ROUND(SUM(token_balance), 0) AS total_supplyFROMsolana_utils.latest_balancesGROUP BYtoken_mint_address),-- calculates the 24h trading volume for each tokentoken_trades AS (SELECTtoken_bought_mint_address,ROUND(SUM(amount_usd), 0) AS trading_volume_24hFROMdex_solana.tradesWHEREblock_time >= NOW() - INTERVAL '24' HOURGROUP BYtoken_bought_mint_address),-- create sub-query containing all relevant token detailstoken_details AS (SELECTt.token_mint_address,f.name,f.symbol,t.token_birth_date,s.total_supply,COALESCE(p_current.price, 0) AS current_price,CASEWHEN COALESCE(p_current.price, 0) * s.total_supply IS NOT NULLAND IS_FINITE(COALESCE(p_current.price, 0) * s.total_supply) THEN CAST(COALESCE(p_current.price, 0) * s.total_supply AS DECIMAL (38, 0))ELSE 0END AS market_cap_usd,COALESCE(tt.trading_volume_24h, 0) AS trade_volume_usdFROMtokens tLEFT JOIN tokens_solana.fungible f ON t.token_mint_address = f.token_mint_addressLEFT JOIN token_supply s ON t.token_mint_address = s.token_mint_addressLEFT JOIN dex_solana.price_hour p_current ON t.token_mint_address = p_current.contract_addressAND p_current.hour = (SELECTMAX(hour)