Query editor
WITH sol_price AS (SELECTminute,priceFROM prices.usdWHERE contract_address IS NULLAND symbol = 'SOL'),all_transactions AS (SELECTcall_tx_id AS tx_id,call_block_time AS block_time,account_to,account_from,CASEWHEN account_to = 'RRHjLz4vDDd9Ug7hmzW3NAzWUqsKnmgvs1yegDanAPN' THEN 'Receive'WHEN account_from = 'RRHjLz4vDDd9Ug7hmzW3NAzWUqsKnmgvs1yegDanAPN' THEN 'Send'END AS action_type,(lamports/1e9) AS total_sol,(lamports/1e9 * price) AS total_usd_solFROM system_program_solana.system_program_call_transferLEFT JOIN sol_price ON date_trunc('minute', call_block_time) = minuteWHERE DATE(call_block_time) > DATE('2024-03-30')AND (account_to = 'RRHjLz4vDDd9Ug7hmzW3NAzWUqsKnmgvs1yegDanAPN'OR account_from = 'RRHjLz4vDDd9Ug7hmzW3NAzWUqsKnmgvs1yegDanAPN')),aggregated_transactions AS (SELECTdate_trunc('hour', block_time) AS date_time,action_type,SUM(total_sol) AS total_sol,SUM(total_usd_sol) AS total_usd_solFROM all_transactionsGROUP BY 1, 2)SELECTdate_time,SUM(CASE WHEN action_type = 'Receive' THEN total_sol ELSE 0 END) AS total_sol_received,SUM(CASE WHEN action_type = 'Receive' THEN total_usd_sol ELSE 0 END) AS total_usd_received,SUM(CASE WHEN action_type = 'Send' THEN total_sol ELSE 0 END) AS total_sol_sent,SUM(CASE WHEN action_type = 'Send' THEN total_usd_sol ELSE 0 END) AS total_usd_sent,SUM(SUM(CASE WHEN action_type = 'Receive' THEN total_sol ELSE -total_sol END)) OVER (ORDER BY date_time) AS cumulative_net_sol,SUM(SUM(CASE WHEN action_type = 'Receive' THEN total_usd_sol ELSE -total_usd_sol END)) OVER (ORDER BY date_time) AS cumulative_net_usdFROM aggregated_transactionsGROUP BY 1ORDER BY 1 DESC;