Query editor
/*Forked from @datafi/LayerZero User Statsby @scarn_ethPlain English Explanation:This query retrieves user statistics for a given address. It calculates:- the number of transactions,- the number of double-checked records,- the average number of transactions for all users, and- the total number of users. It also calculates- the percentage ranking of the given address among all users, with a minimum value of 0.01%.The query uses multiple subqueries and joins different tables to gather the necessary data.- It starts by creating a temporary table called "lzr_ep" that combines data from various tables based on specific conditions. Then,- it creates another temporary table called "chain_id" that assigns chain IDs to their corresponding names. Next,- it creates a temporary table called "user_stats" that calculates the number of transactions and double-checked records for each user address. Finally,- it selects the desired columns from the "user_stats" table and performs calculations to determine the ranking and percentage for the given address.Questions this query could help answer:- How many transactions does a specific user address have?- What is the average number of transactions for all users?- How does a specific user address rank among all users in terms of transaction count?- What is the total number of users?https://sqlgenius.app/sql-explainer*/WITH lzr_ep AS(--110 ArbitrumSELECTep.contract_address, -- contract addressep.call_tx_hash, -- call txn hash110 AS _srcchainid, -- source chain 110 is Arbitrumep._dstchainid, -- destination chaint."from" AS user_address -- txn from addressFROMlayerzero_arbitrum.endpoint_call_send ep -- FROM l0 endpointINNER JOINarbitrum.transactions t -- JOIN arbitrum txnsON ep.call_tx_hash = t.hash -- ON txn hashAND ep.call_success -- but only successful txnsUNION ALL -- UNION--101 Ethereum ---------------------------------SELECTep.contract_address,ep.call_tx_hash,110 AS _srcchainid,ep._dstchainid,t."from" AS user_addressFROMlayerzero_ethereum.endpoint_call_send epINNER JOINethereum.transactions tON ep.call_tx_hash = t.hashAND ep.call_successUNION ALL ----------------------------------------102 BNB --------------------------------------SELECT