Be forewarned: I'm new to MySQL so expect stupid follow-up questions.
I am writing an application that keeps track of exam scores for students. Each student will have multiple exams taken at different times. I want to be able to calculate the change in the exam scores between two consecutive exams for the same student. Here is the basic structure of my table...
--------------------------------------------
| score_id | student_id | date | score |
--------------------------------------------
| 1| 1| 2011-6-1 | 15 |
| 21| 1| 2011-8-1 | 16 |
| 342| 1| 2012-3-1 | 18 |
| 4| 2| 2011-6-1 | 21 |
| 16| 2| 2011-8-1 | 20 |
| 244| 2| 2012-3-1 | 20 |
--------------------------------------------
What I would like to return from my Query is...
---------------------
| score_id | growth |
---------------------
| 1| NULL|
| 21| 1|
| 342| 2|
| 4| NULL|
| 16| -1|
| 244| 0|
---------------------
It is a similar question to the on asked here , but the dates are not always a specific time apart from one another.