Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. select id,
  2. number_sequ,
  3. startvalue
  4. lead(startvalue,1,0) over (partition by id order by number_sequ) AS End_value
  5. from mytable
  6.  
  7. id number_sequ startvalue End_value
  8. ---- ----- ---------- -----------
  9. AAA 1 30 20
  10. AAA 2 20 10
  11. AAA 4 10 15
  12. AAA 5 15 0
  13. BBB 1 12 23
  14. BBB 3 23 34
  15. BBB 4 34 0
  16.  
  17. id number_sequ startvalue End_value
  18. ---- ----- ---------- -----------
  19. AAA 3
  20. BBB 2
  21.  
  22. INSERT INTO mytable (id,number_sequ,startvalue)
  23. select id ,number_sequ ,'0' from mytable where (some condition to specify missing data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement