Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Redefinir a soma quando a condição for atendida no Oracle


Você pode criar subgrupo usando soma condicional:
WITH cte AS (
   SELECT t.*,SUM(CASE WHEN hour=3 THEN 1 ELSE 0 END) OVER(ORDER BY timestamp) grp
   FROM t
)
SELECT cte.*, SUM(Count) OVER(PARTITION BY grp ORDER BY timestamp) AS total
FROM cte