Query editor
/*Plain English Explanation:This query calculates a rank score for each user based on various criteria and sorts the results in descending order of the rank score. The rank score is calculated by adding up points for different conditions met by the user.The query first creates a summary table called "user_summary" which aggregates data from the "layerzero.send" table. It calculates various metrics such as transaction count, initial and last block time, age in days, active source and destination chain count, active transaction contract count, active days, weeks, and months count, and the total amount bridged in USD.Then, the query creates another table called "user_summary_with_rank" which adds a rank score column to the "user_summary" table. The rank score is calculated by adding up points for different conditions met by the user. For example, if a user has conducted transactions to 2 destination chains, they get 1 point. If they have conducted transactions during 2 distinct months, they get 1 point, and so on.Finally, the query selects specific columns from the "user_summary_with_rank" table, including the rank number, user address, rank score, transaction count, amount bridged in USD, active chain counts, active days/weeks/months counts, age in days, and initial block time. The results are sorted in descending order of the rank score, amount bridged, and transaction count.Questions this query could help answer:Who are the top-ranked users based on their activity and amount bridged?What is the rank score, transaction count, and amount bridged for each user?How many active source chains, destination chains, and transaction contracts does each user have?How many active days, weeks, and months has each user conducted transactions?How long have users been using Layer Zero (age in days)?What is the initial block time for each user?Source: https://sqlgenius.app/sql-explainer*/with user_summary as (select userss,count(*) as transaction_count,min(block_time) as initial_block_time,max(block_time) as last_block_time,date_diff('day', min(block_time), now()) as lz_age_days,count(distinct source_chain_id) as active_source_chain_count,count(distinct destination_chain_id) as active_destination_chain_count,count(distinct transaction_contract) as active_transaction_contract_count,count(distinct date_trunc('day', block_time)) as active_days_count,count(distinct date_trunc('week', block_time)) as active_weeks_count,count(distinct date_trunc('month', block_time)) as active_months_count,-- coalesce(sum(amount_usd / power(10, p.decimals) * p.price), 0) as amount_usdcoalesce(sum(amount_usd), 0) as amount_usdfrom layerzero.sendgroup by 1),user_summary_with_rank as (select *,(active_source_chain_count -- Count of used source chains+ if(active_destination_chain_count >= 2, 1, 0) -- Conducted transactions to 2 destination chains+ if(active_destination_chain_count >= 5, 1, 0) -- Conducted transactions to 5 destination chains+ if(active_destination_chain_count >= 10, 1, 0) -- Conducted transactions to 10 destination chains+ if(active_months_count >= 2, 1, 0) -- Conducted transactions during 2 distinct months+ if(active_months_count >= 6 , 1, 0) -- Conducted transactions during 6 distinct months+ if(active_months_count >= 9, 1, 0) -- Conducted transactions during 9 distinct months+ if(active_months_count >= 12, 1, 0) -- Conducted transactions during 12 distinct months+ if(active_weeks_count >= 10, 1, 0) -- Conducted transactions during 10 distinct weeks+ if(active_weeks_count >= 20, 1, 0) -- Conducted transactions during 20 distinct weeks+ if(active_weeks_count >= 50, 1, 0) -- Conducted transactions during 50 distinct weeks+ if(active_weeks_count >= 100, 1, 0) -- Conducted transactions during 100 distinct weeks+ if(active_days_count >= 50, 1, 0) -- Conducted transactions during 50 distinct days+ if(active_days_count >= 100, 1, 0) -- Conducted transactions during 100 distinct days