I have been trying to do a running total "order by date". The problem is that if you have two entries with the same date, then it shows the same total on both rows.
Table structure is something like this
sipID|Date|Amount
1|2017-11-07|2
2|2017-11-09|27
3|2017-11-07|24
So I know how to do a running total by id like this.
SELECT `sipID`,DATE_FORMAT(`Date`,'%d %M %Y') as `DateFormat`,`Amount`,
(SELECT SUM(`Amount`) FROM `salesinvoice_payments` as `Lin` WHERE `Lin`.`sipID`<=`Lout`.`sipID` && `salesinvoice_id`=115) as `Balance`
FROM `salesinvoice_payments` as `Lout`
WHERE `salesinvoice_id`=115
ORDER BY `sipID`
But I wanted it to be ordered by date ascending so I did this
SELECT `sipID`,DATE_FORMAT(`Date`,'%d %M %Y') as `DateFormat`,`Amount`,
(SELECT SUM(`Amount`) FROM `salesinvoice_payments` as `Lin` WHERE `Lin`.`Date`<=`Lout`.`Date` && `salesinvoice_id`=115) as `Balance`
FROM `salesinvoice_payments` as `Lout`
WHERE `salesinvoice_id`=115
ORDER BY `Date` ASC
Now this does work. The problem happens when you have 2 rows with the same date. What happens then is that both rows have the same running total. eg
07 November 2017 2.00 24.00
07 November 2017 22.00 24.00
09 November 2017 3.00 27.00
What I want is this
07 November 2017 2.00 2.00
07 November 2017 22.00 24.00
09 November 2017 3.00 27.00
Is there a workaround so that I can have a proper running total, and have it ordered by date without it getting the same total on the same date?
EDIT: @Strawberry: I have finally worked out how sqlfiddle works, and put this for my original question. http://www.sqlfiddle.com/#!9/c6dc75/1