MY question deals with month to month data changes..I want a simple (if possible) SQL query that will show the person , and month change grouped by person/month or similar.. the important part is to show gains and losses.
For Example I have a table: (date simplified )
id | Date | Person | Sales
---|-----------|--------| -----
1 | 2010-9-01 | Alice | 5
2 | 2010-8-01 | Alice | 2
3 | 2010-9-01 | Peter | 2
4 | 2010-8-01 | Peter | 3
5 | 2010-9-01 | Bob | 5
6 | 2010-8-01 | Bob | 7
From this table I'm looking to get a report like this.
Month | Person | Sales_total | Gain-Loss_from_Previous_month |
------ -------- ------------- -------------------------------
2010-9 Alice 7 +3
2010-9 Peter 5 -1
2010-9 Bob 12 -2
Can this be done as a pure MySQL query? O