Query editor
WITHstake_red_inicial AS (SELECTSUM(amount_staked)- SUM(amount_full_withdrawn) AS stake_inicial_redFROM staking_ethereum.flowsWHERE block_time < TIMESTAMP '2023-05-01'),stake_inicial AS (SELECTentity,SUM(amount_staked)- SUM(amount_full_withdrawn) AS stake_mayo_2023FROM staking_ethereum.flowsWHERE block_time < TIMESTAMP '2023-05-01'AND entity IN ('Lido', 'Coinbase', 'Binance')GROUP BY entity),flujos_mensuales AS (SELECTDATE_TRUNC('month', block_time) AS mes,entity,SUM(amount_staked) AS eth_depositado,SUM(amount_full_withdrawn) AS eth_retirado_completoFROM staking_ethereum.flowsWHERE block_time >= TIMESTAMP '2023-05-01'AND block_time <= TIMESTAMP '2026-03-31'AND entity IN ('Lido', 'Coinbase', 'Binance')GROUP BY 1, 2),stake_entidad AS (SELECTf.mes,f.entity,i.stake_mayo_2023+ SUM(f.eth_depositado - f.eth_retirado_completo)OVER (PARTITION BY f.entityORDER BY f.mesROWS BETWEEN UNBOUNDED PRECEDINGAND CURRENT ROW) AS stake_acumuladoFROM flujos_mensuales fJOIN stake_inicial i ON f.entity = i.entity),flujos_red_mensuales AS (SELECTDATE_TRUNC('month', block_time) AS mes,SUM(amount_staked) AS eth_depositado_red,SUM(amount_full_withdrawn) AS eth_retirado_redFROM staking_ethereum.flowsWHERE block_time >= TIMESTAMP '2023-05-01'AND block_time <= TIMESTAMP '2026-03-31'GROUP BY 1),