clear markdown compare help best fiddles feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3601472 fiddles created (47964 in the last week).

CREATE TABLE sales(date date, sales int, rest int);
 hidden batch(es)


INSERT INTO sales VALUES ('20170101', 52, 0);
 hidden batch(es)


INSERT INTO sales VALUES ('20170102', 30, 0);
 hidden batch(es)


INSERT INTO sales VALUES ('20170103', 10, 200);
 hidden batch(es)


SELECT date, sales, rest FROM ( SELECT t.date, t.sales, @acm := @acm + t.rest + @last_sales AS rest, @last_sales := t.sales FROM sales t, (SELECT @last_sales := 0, @acm := 0) r ORDER BY t.date desc ) X ORDER BY date;
date sales rest
2017-01-01 52 240
2017-01-02 30 210
2017-01-03 10 200
 hidden batch(es)