Query editor
WITH data AS (SELECTname as token_name,coalesce(token_bought_symbol, symbol) as token_bought_symbol,token_bought_mint_address,created_at as token_created_at,MAX(block_time) as last_trade_at,COUNT(tx_id) AS trades,SUM(amount_usd) AS volume_usd,COUNT(DISTINCT token_pair) AS pairs,COUNT(DISTINCT trader_id) AS traders,case when COUNT(DISTINCT token_pair) > 0 thenCOUNT(tx_id) / COUNT(DISTINCT token_pair)end AS pairs_to_trades_ratio,case when COUNT(DISTINCT token_pair) > 0 thenCOUNT(DISTINCT trader_id) / COUNT(DISTINCT token_pair)end AS pairs_to_traders_ratio,case when COUNT(DISTINCT token_pair) > 0 thenSUM(amount_usd) / COUNT(DISTINCT token_pair)end AS pairs_to_volume_ratio,case when SUM(amount_usd) > 0 thenCOUNT(DISTINCT trader_id) / SUM(amount_usd)end AS avg_trader_volume_usdFROM dex_solana.tradesLEFT JOIN tokens_solana.fungible ti on ti.token_mint_address = token_bought_mint_addressWHEREblock_month = date_trunc('month', now()) - interval '2' monthGROUP BY1,2,3,4HAVINGCOUNT(tx_id) > 10000)SELECT*,NTILE(10) OVER (ORDER BY pairs) AS pairs_decile,NTILE(10) OVER (ORDER BY trades) AS trades_decile,NTILE(10) OVER (ORDER BY volume_usd) AS volume_usd_decile,NTILE(10) OVER (ORDER BY traders) AS traders_decile,NTILE(10) OVER (ORDER BY pairs_to_trades_ratio) AS pairs_to_trades_ratio_decile,NTILE(10) OVER (ORDER BY pairs_to_traders_ratio) AS pairs_to_traders_ratio_decile,NTILE(10) OVER (ORDER BY pairs_to_volume_ratio) AS pairs_to_volume_ratio_decile,NTILE(10) OVER (ORDER BY avg_trader_volume_usd) AS avg_trader_volume_usd_decileFROM data