Suppose I have this code
create temporary table somedata (a integer);
insert into somedata (a) values (11), (25), (62); --#these values are always increasing
select * from somedata;
giving this
+--+
|a |
+--+
|11|
|25|
|62|
+--+
How do I calculate a column of values 'b' where each one is the difference between the value of 'a' in the current row and the value of 'a' in the preceding row?
+--+--+
|a |b |
+--+--+
|11| 0| # ie 11-11 since theres no preceding row
|25|14| # ie 25-11
|62|37| # ie 62-25 etc
+--+--+
This is so obvious in openoffice or excel that I feel a bit silly not having yet found how to do this on MySql's site nor anywhere else.