My tables are:
Bowlers: BName - Handed - Phone
Performances: BName - TName - Score
Tournaments: TName - TDate
I am trying to figure out how to calculate the difference in score for a bowler named Fred. My code so far is:
select tname, tdate, score
from tournaments
natural inner join
performances
where bname = 'Fred'
order by tdate;
This gives me a table like this:
TName TDate Score
------------------------ ------------ -------------
Tournament 1 1/1/2014 250
Tournament 2 1/8/2014 245
Tournament 3 2/10/2014 215
Now I just need to add a fourth column that calculates the difference in his score from the previous tournament. So the finished table would look like this:
TName TDate Score Score_Dif
------------------------ ------------ ------------- -------------
Tournament 1 1/1/2014 250 0
Tournament 2 1/8/2014 245 -5
Tournament 3 2/10/2014 215 -30
Any help is greatly appreciated!