Window Function LEAD
08 Jul 2019This article is an extension of the window function, to follow up on each of the window functions.
The LEAD
function returns values in an offset row. The offset is given by the second argument to the function itself. The offset pushes the index below (or after) the selected row.
To demonstrate the effect of this function, we’ll take the sales_id
value, and then we’ll also take a led sales_id
. By adjusting the offset value, you’ll see how the leaded value ascends up the rows.
sale_id | lead |
---|---|
1 | 2 |
2 | 3 |
3 | 4 |
4 | 5 |
5 | 6 |
Adjusting the index so that it’s now 2
; the lead row is now offset by 2.
sale_id | lead |
---|---|
1 | 3 |
2 | 4 |
3 | 5 |
4 | 6 |
5 | 7 |