show cumulative/running total
I have a results page with a Date column where I'm displaying the total records grouped by month, in the following format:
MONTH TOTAL
Jan 16 2
Feb 16 4
Mar 16 6
Apr 16 6
May 16 11
My SELECT statement is as follows:
SELECT *, YEAR(StagingDate), MONTH(StagingDate), COUNT(*) as recordCount FROM clients JOIN accountants on clients.AccountantID = accountants.AccountantID WHERE StagingDate IS NOT NULL AND accountants.AccountantID = %s GROUP BY EXTRACT(YEAR_MONTH FROM StagingDate) ORDER BY StagingDate ASC.
I would now like to display a running total in another column, like this:
MONTH TOTAL RUNNING TOTAL
Jan 16 2 2
Feb 16 4 6
Mar 16 6 12
Apr 16 6 18
May 16 11 29
How would I change my SELECT statement to calculate this, or could it be done in PHP?