sql >> Base de Datos >  >> RDS >> Oracle

Restablecer suma cuando se cumple la condición en Oracle

Podrías crear un subgrupo usando la suma 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