Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT value - (previous.value) FROM table
- select t1.value - t2.value from table t1, table t2
- where t1.primaryKey = t2.primaryKey - 1
- select rank() OVER (ORDER BY id) as 'Rank', value into temp1 from t
- select t1.value - t2.value from temp1 t1, temp1 t2
- where t1.Rank = t2.Rank - 1
- drop table temp1
- SELECT value - (
- SELECT TOP 1 value
- FROM mytable m2
- WHERE m2.col1 < m1.col1 OR (m2.col1 = m1.col1 AND m2.pk < m1.pk)
- ORDER BY
- col1, pk
- )
- FROM mytable m1
- ORDER BY
- col1, pk
- declare @temp (value int, primaryKey int, tempid int identity)
- insert value, primarykey from mytable order by primarykey
- select t1.value - t2.value from @temp t1
- join @temp t2
- on t1.tempid = t2.tempid - 1
Add Comment
Please, Sign In to add comment