我先拿到一些“我一夫”会分几行的数据,我想从前几行中分出一行,再说一遍。
因此,下表是:
CREATE TABLE foo ( id, length )
INSERT INTO foo (id,length) VALUES(1,1090) INSERT INTO foo (id,length) VALUES(2,888) INSERT INTO foo (id,length) VALUES(3,545) INSERT INTO foo (id,length) VALUES(4,434) INSERT INTO foo (id,length) VALUES(5,45)
我想,结果显示第三栏“差异”,即从以下一栏中减去最后的零减。
+------+------------------------+ | id |length | difference | +------+------------------------+ | 1 | 1090 | 202 | | 2 | 888 | 343 | | 3 | 545 | 111 | | 4 | 434 | 389 | | 5 | 45 | 45 |
我尝试了自我参与,但我并不确切地确定如何限制结果,而不是让结果本身循环。 我可以肯定的是,如果某个特定结果设定,那么不使用这种价值,那么这种补贴的价值将依次计算。 我可以扩大该表,以包括某种顺序价值。
这是我所尝试的:
SELECT id, f.length, f2.length, (f.length - f2.length) AS difference FROM foo f, foo f2
请你协助。