Query editor
/* Return the final result */WITH period_entity AS (SELECT*FROM (SELECT DISTINCTDATE_TRUNC('day', block_time) AS periodFROM staking_ethereum.deposits) AS tmp1CROSS JOIN (SELECT DISTINCTentity_categoryFROM staking_ethereum.deposits) AS tmp2UNION ALLSELECT DISTINCTDATE_TRUNC('day', block_time) AS period,'ETC' AS entity_categoryFROM staking_ethereum.deposits), steth_tmp AS (SELECTDATE_TRUNC('day', block_time) AS period,COALESCE(entity_category, 'ETC') AS depositor_entity_category,SUM(amount_staked) AS amount,COUNT(*) AS num_of_depositsFROM staking_ethereum.depositsWHERENOT block_time IS NULLGROUP BY1,2), steth AS (SELECTpe.period,pe.entity_category,COALESCE(amount, 0) AS amount,COALESCE(num_of_deposits, 0) AS num_of_depositsFROM period_entity AS peLEFT JOIN steth_tmp AS stON pe.period = st.period AND pe.entity_category = st.depositor_entity_category), cumulative_steth AS (SELECT*,SUM(amount) OVER (PARTITION BY entity_category ORDER BY period) AS total_amount,SUM(num_of_deposits) OVER (PARTITION BY entity_category ORDER BY period) AS total_num_of_depositsFROM steth), entities AS (SELECT DISTINCTentity,MIN(category) AS categoryFROM staking_ethereum.entitiesWHERENOT entity IS NULLGROUP BY1)SELECTcumulative_steth.*,categoryFROM cumulative_steth