In SQL Server, LEAD()
is a window function that allows us to access a value from a later row in the same result set, without the need to perform a self-join.
We specify the row as an offset from the current row. An offset of 1
means it gets the value from the next row, an offset of 2
means two rows forward, and so on.