Query editor
WITH raw AS (SELECTtransaction_type,COUNT(*) AS tx_countFROM xrpl.transactionsWHERE ledger_close_date >= CURRENT_DATE - INTERVAL '30' DAYGROUP BY 1),total AS (SELECT SUM(tx_count) AS total_count FROM raw),ranked AS (SELECTtransaction_type,tx_count,ROW_NUMBER() OVER (ORDER BY tx_count DESC) AS rnFROM raw)SELECTCASE WHEN rn <= 7 THEN transaction_type ELSE 'Others' END AS transaction_type,SUM(tx_count) AS tx_count,ROUND(SUM(tx_count) * 100.0 / MAX(t.total_count), 1) AS pctFROM ranked rCROSS JOIN total tGROUP BY 1ORDER BY 2 DESC