Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
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;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear