1) Get the 2nd to last row
2) Get the last row
3) Do the summation
4) add one more row.
Now, I'm going to go out on a limb, and guess that your question is REALLY: How do I know when I get to the last two rows?
you either need to query the result set to see how many rows there are ahead of time (I'm not sure if this is possible), or you need to save each row as it comes in. Then, when you get the next row, move the previous one up, and save this one...in other words, you have:
each time you read a row, you move what's in lastRowData to secondLastRow, and then store the current in lastRow.
you then have to account for the possibility that you have zero or one row, but that shouldn't be too hard.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors