假设我有这个代码
create temporary table somedata (a integer);
insert into somedata (a) values (11), (25), (62); --#these values are always increasing
select * from somedata;
给这个
+--+
|a |
+--+
|11|
|25|
|62|
+--+
如何计算一列值“b”,其中每个值是当前行中“a”值与前一行中“a”值之间的差值?
+--+--+
|a |b |
+--+--+
|11| 0| # ie 11-11 since theres no preceding row
|25|14| # ie 25-11
|62|37| # ie 62-25 etc
+--+--+
这在 openoffice 或 excel 中是如此明显,以至于我觉得在 MySql 的网站或其他任何地方都没有找到如何做到这一点有点傻。