Query editor
WITH RECURSIVE TransactionHierarchy ("from", "to", depth, total_value, transaction_count) AS (SELECTet1."from",et1."to",1 AS depth,SUM(et1.value) AS total_value,COUNT(et1.hash) AS transaction_countFROM ethereum.transactions et1WHERE et1."to" = {{address}} -- 查询起始地址GROUP BY et1."from", et1."to"HAVING COUNT(et1.hash) > 0UNION ALL-- 递归查找相关交易SELECTet2."from",et2."to",th.depth + 1 AS depth,SUM(et2.value) AS total_value,COUNT(et2.hash) AS transaction_countFROM ethereum.transactions et2INNER JOIN TransactionHierarchy thON et2."to" = th."from"WHERE th.depth < {{hop}}GROUP BY et2."from", et2."to", th.depthHAVING COUNT(et2.hash) > 0),RankedTransactions ("from", "to", depth, total_value, transaction_count, rn) AS (SELECT"from","to",depth,total_value,transaction_count,ROW_NUMBER() OVER (PARTITION BY depth ORDER BY transaction_count DESC) AS rnFROM TransactionHierarchy)SELECT "from", "to", depth, total_value, transaction_countFROM RankedTransactionsWHERE rn <= {{limitNumber}};