I have a table as follows:
I just want the previous entry for every row from the column ‘marks’.
This is my query:
select *,LAG(marks,1,marks) OVER (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as prev
from student_tests
This is the output:
The output is as per my expectation. But, I am unable to figure out if it makes sense when I give 1 as the offset in the part LAG(marks,1,marks) along with the window.
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
Because, I am in the sense asking SQL to look ‘UNBOUNDED’ PRECEDING and then giving 1 in the offset doesn’t seem sensible to me.
Am I missing something?
Please help me understand this.