Skip to content

Instantly share code, notes, and snippets.

@artyom
Created February 1, 2012 16:05
Show Gist options
  • Save artyom/1717729 to your computer and use it in GitHub Desktop.
Save artyom/1717729 to your computer and use it in GitHub Desktop.
subsequent rows values difference
sqlite> select * from t1;
i n
a 1
b 2
c 3
d 4
e 5
foo 15
bar 37
baz 115
zzz 85
sqlite> select t1.i, t2.i, t1.n, t2.n, t1.n-t2.n as difference from t1, t1 as t2 where t1.oid=t2.oid+1;
i i n n difference
b a 2 1 1
c b 3 2 1
d c 4 3 1
e d 5 4 1
foo e 15 5 10
bar foo 37 15 22
baz bar 115 37 78
zzz baz 85 115 -30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment