Query editor
Withtokenprice as (select minute,symbol,token,price FROM query_3265731),OpenFee as (selectday,SUM(totalFee*COALESCE(price,1)) as totalFee,SUM(daoAmount*COALESCE(price,1)) as daoAmount,SUM(brokerAmount *COALESCE(price,1)) as brokerAmount,SUM(alpPoolAmount *COALESCE(price,1)) as alpPoolAmountFROM query_3277042 aLEFT JOIN tokenprice ON a.date_min = minute AND tokenIn_contract_address = CAST(tokenprice.token AS VARCHAR)GROUP BY 1),CloseFee as (selectday,SUM(totalFee*COALESCE(price,1)) as totalFee,SUM(daoAmount*COALESCE(price,1)) as daoAmount,SUM(brokerAmount *COALESCE(price,1)) as brokerAmount,SUM(alpPoolAmount *COALESCE(price,1)) as alpPoolAmountFROM query_3277056 aLEFT JOIN tokenprice ON a.date_min = minute AND tokenIn_contract_address = CAST(tokenprice.token AS VARCHAR)GROUP BY 1),open as (select date_trunc('day',block_time) as day FROM query_3265203),dt_1 as ( -- act as system dateselect distinct day FROM open), agg as (SELECTdt_1.day,SUM( COALESCE(OpenFee.totalFee,0) + COALESCE(CloseFee.totalFee,0) ) as totalFee,SUM( COALESCE(OpenFee.daoAmount,0) + COALESCE(CloseFee.daoAmount,0) ) as daoAmount,SUM( COALESCE(OpenFee.brokerAmount,0) + COALESCE(CloseFee.brokerAmount,0) ) as brokerAmount,SUM( COALESCE(OpenFee.alpPoolAmount,0) + COALESCE(CloseFee.alpPoolAmount,0) ) as alpPoolAmountFROMdt_1LEFT JOIN OpenFee ON dt_1.day = OpenFee.dayLEFT JOIN CloseFee ON dt_1.day = CloseFee.dayGROUP BY 1)SELECTday,totalFee AS daily_feeIncome,alpPoolAmount AS LPPoolIncome-- ,daoAmount AS daoAmount,brokerAmount AS platformAndRepurchaseAmount,SUM(totalFee) OVER(ORDER BY day asc ) AS cumulative_feeIncome,SUM(alpPoolAmount) OVER(ORDER BY day asc ) AS cumulative_LPPoolIncomeFROMagg