Query editor
WITH stusr_actions AS (SELECTdate_trunc('day', evt_block_time) AS action_day,_usrAmount / 1e18 AS amount,'deposit' AS actionFROM resolv_ethereum.StUSR_evt_DepositUNION ALLSELECTdate_trunc('day', evt_block_time) AS action_day,-(_usrAmount / 1e18) AS amount,'withdraw' AS actionFROM resolv_ethereum.StUSR_evt_Withdraw),usr_actions AS (SELECTdate_trunc('day', call_block_time) AS action_day,_amount / 1e18 AS amount,'mint' AS actionFROM resolv_ethereum.ResolUSD_call_mintUNION ALLSELECTdate_trunc('day', call_block_time) AS action_day,-(_amount / 1e18) AS amount,'burn' AS actionFROM resolv_ethereum.ResolUSD_call_burn),all_actions AS (SELECT action_day, amount, 'stusr' AS source FROM stusr_actionsUNION ALLSELECT action_day, amount, 'usr' AS source FROM usr_actions),daily_totals AS (SELECTaction_day,SUM(CASE WHEN source = 'stusr' THEN amount ELSE 0 END) AS stusr_amount,SUM(CASE WHEN source = 'usr' THEN amount ELSE 0 END) AS usr_amountFROM all_actionsGROUP BY action_day),cumulative_sums AS (SELECTaction_day,SUM(stusr_amount) OVER (ORDER BY action_day) AS cumulative_stusr,SUM(usr_amount) OVER (ORDER BY action_day) AS cumulative_usrFROM daily_totals)SELECTaction_day AS action_time,cumulative_stusr,cumulative_usr,CASEWHEN cumulative_usr = 0 THEN NULLELSE (cumulative_stusr / cumulative_usr) * 100END AS stusr_percentageFROM cumulative_sumsORDER BY action_time;