clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1811954 fiddles created (25259 in the last week).

CREATE TABLE `table1` ( `id` int(11) NOT NULL, `date` datetime NOT NULL DEFAULT current_timestamp(), `payment` double NOT NULL ); INSERT INTO `table1` (`id`, `date`, `payment`) VALUES (1, '2021-02-16 12:00:00', 100), (2, '2021-02-17 12:00:00', 200), (3, '2021-02-18 12:00:00', 300), (4, '2021-02-19 12:00:00', 400), (5, '2021-02-20 12:00:00', 500), (6, '2021-02-21 12:00:00', 600), (7, '2021-02-22 12:00:00', 700); version();
 hidden batch(es)


SELECT DATE_FORMAT(date, "%Y-%m-%d") AS date, payment, SUM(payment) OVER(ORDER BY id) AS balance FROM table1 WHERE date BETWEEN '2021-02-19 12:00:00'AND '2021-02-21 12:00:00';
date payment balance
2021-02-19 400 400
2021-02-20 500 900
2021-02-21 600 1500
 hidden batch(es)