Query editor
-- Notes: Do not wrap indexed column like DATE(block_time) as this prevents the query from using the index efficiently.WITH programs AS (SELECTnamespace,executing_account,COUNT(*) AS calls,approx_distinct(tx_signer) AS users --use approx_distinct vs COUNT(DISTINCT) to optimize/speed up query. Uses less computation with small sacrifice to accuracy (2.3%). See: https://trino.io/docs/current/functions/aggregate.html#approx_distinctFROM solana.instruction_calls aLEFT JOIN solana.programs b ON a.executing_account = b.program_idWHERE block_time >= NOW() - INTERVAL '24' hourAND tx_success = TRUEGROUP BY 1, 2ORDER BY 3 DESCLIMIT 100),programs_7d AS (SELECTa.executing_account,COUNT(*) AS calls_7d,approx_distinct(a.tx_signer) AS users_7dFROM solana.instruction_calls aINNER JOIN programs b ON a.executing_account = b.executing_accountWHERE block_time >= NOW() - INTERVAL '7' day AND block_time < NOW() - INTERVAL '6' day -- filter by 24hr window 7 days agoAND tx_success = TRUEGROUP BY 1),programs_30d AS (SELECTa.executing_account,COUNT(*) AS calls_30d,approx_distinct(a.tx_signer) AS users_30dFROM solana.instruction_calls aINNER JOIN programs b ON a.executing_account = b.executing_accountWHERE block_time >= NOW() - INTERVAL '30' day AND block_time < NOW() - INTERVAL '29' day -- filter by 24hr window 30 days agoAND tx_success = TRUEGROUP BY 1)SELECT DISTINCTCOALESCE(a.namespace, labels.program_name, sector_labels.program_name, 'Unknown') as name, --add any missing labels from additional datasetCONCAT('<a href="https://solscan.io/account/', a.executing_account, '" target="_blank">', a.executing_account, '</a>') as executing_account,COALESCE(sector_labels.sector, 'Unknown') as Sector,'|' as divider_1,a.calls,CAST(calls AS DOUBLE)/CAST(calls_7d AS DOUBLE) - 1 AS calls_7d,CAST(calls AS DOUBLE)/CAST(calls_30d AS DOUBLE) - 1 AS calls_30d,'|' as divider_2,a.users,CAST(users AS DOUBLE)/CAST(users_7d AS DOUBLE) - 1 AS users_7d,CAST(users AS DOUBLE)/CAST(users_30d AS DOUBLE) - 1 AS users_30d,'|' as divider_3,retention_rate_after_1d,retention_rate_after_7dFROM programs aLEFT JOIN programs_7d b ON a.executing_account = b.executing_accountLEFT JOIN programs_30d c ON a.executing_account = c.executing_accountLEFT JOIN query_4381048 retention on a.executing_account = retention.executing_account --program retention data