Soldato
I have a table that stores scores for each person each day eg:
id date score
1 date1 1000
2 date1 400
3 date1 700
1 date2 900
2 date2 400
3 date2 200
1 date3 800
2 date3 200
3 date3 100 etc.
What I want to find out is what the difference between each score for each person each day, so I end up with this:
id datea dateb diff
1 date1 date2 100
1 date2 date3 100
2 date1 date2 100
2 date2 date3 200
3 date1 date2 500
3 date2 date3 100
Any ideas on how to accomplish this? The limitation I have is that my host is using an older version of MySQl so I can't use limits in sub selects, can't create functions or views etc so it all has to be in one query. I was thinking of some kind of self join, but that brings back too many irrelevant rows (e.g. date 1 - date 3).
id date score
1 date1 1000
2 date1 400
3 date1 700
1 date2 900
2 date2 400
3 date2 200
1 date3 800
2 date3 200
3 date3 100 etc.
What I want to find out is what the difference between each score for each person each day, so I end up with this:
id datea dateb diff
1 date1 date2 100
1 date2 date3 100
2 date1 date2 100
2 date2 date3 200
3 date1 date2 500
3 date2 date3 100
Any ideas on how to accomplish this? The limitation I have is that my host is using an older version of MySQl so I can't use limits in sub selects, can't create functions or views etc so it all has to be in one query. I was thinking of some kind of self join, but that brings back too many irrelevant rows (e.g. date 1 - date 3).