CREATE TABLE entries(
tran_date TIMESTAMP NOT NULL,
amount INT NOT NULL
);
INSERT INTO entries VALUES ('2022-01-01 00:01:00', 100),('2022-01-01 01:01:00', 3400),('2022-01-01 02:01:00', -500),
('2022-01-02 00:01:00', 8000),('2022-01-02 01:01:00', -3900),('2022-01-02 02:01:00', -900);
WITH day_amounts AS(SELECT DATE(tran_date) AS day, SUM(amount) AS amount FROM entries GROUP BY DATE(tran_date))
SELECT day, SUM(amount) OVER (ORDER BY day) AS balance FROM day_amounts;