I have a table date, subs, unsubs, where date is PK, and subs and unsubs are the number of subscribes and unsubscribes on that date.
I want to add a column to calculate the number of total subscribers on each day, that is, if sort date, subsall = subsall of last row + subs – unsubs.
For example: the table is
----------------
2012-01-01, 5, 2
2012-01-02, 6, 1
2012-01-03, 4, 3
----------------
I want to add a new column and the table becomes
-------------------
2012-01-01, 5, 2, 3
2012-01-02, 6, 1, 8
2012-01-03, 4, 3, 9
-------------------
What is the MySQL command to do that?
You are looking for a cumulative sum. Try this: