Как говорит Гордон в комментариях, без сценария это невозможно.
Таким образом, вы можете найти сценарий здесь:
DECLARE update_index INT64 DEFAULT 0;
CREATE TEMP TABLE t1 AS
SELECT index, input, 0 as reset, 0 as reset_group, SUM(input) OVER (ORDER BY index) AS cumsum
FROM UNNEST([4,1,1,-12,1,3,-2,1 ]) AS input WITH OFFSET index;
LOOP
SET update_index = (SELECT MIN(index) FROM t1 WHERE cumsum < 0);
IF update_index IS NULL
THEN
LEAVE;
END IF;
UPDATE t1
SET reset = 1
WHERE index = update_index;
CREATE OR REPLACE TEMP TABLE t1 AS
SELECT *, SUM(IF(reset = 1, 0, input)) OVER (PARTITION BY reset_group ORDER BY index) AS cumsum
FROM (
SELECT index, input, reset, SUM(reset) OVER (ORDER BY index) as reset_group
FROM t1
);
END LOOP;
SELECT *
FROM t1
ORDER BY index;