Guest User

Untitled

a guest
Jun 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. SELECT value - (previous.value) FROM table
  2.  
  3. select t1.value - t2.value from table t1, table t2
  4. where t1.primaryKey = t2.primaryKey - 1
  5.  
  6. select rank() OVER (ORDER BY id) as 'Rank', value into temp1 from t
  7.  
  8. select t1.value - t2.value from temp1 t1, temp1 t2
  9. where t1.Rank = t2.Rank - 1
  10.  
  11. drop table temp1
  12.  
  13. SELECT value - (
  14. SELECT TOP 1 value
  15. FROM mytable m2
  16. WHERE m2.col1 < m1.col1 OR (m2.col1 = m1.col1 AND m2.pk < m1.pk)
  17. ORDER BY
  18. col1, pk
  19. )
  20. FROM mytable m1
  21. ORDER BY
  22. col1, pk
  23.  
  24. declare @temp (value int, primaryKey int, tempid int identity)
  25. insert value, primarykey from mytable order by primarykey
  26.  
  27. select t1.value - t2.value from @temp t1
  28. join @temp t2
  29. on t1.tempid = t2.tempid - 1
Add Comment
Please, Sign In to add comment