LAG(expr [, N[, default]]) [null_treatment] over_clause

Returns the value of expr from the row that lags (precedes) the current
row by N rows within its partition. If there is no such row, the return
value is default. For example, if N is 3, the return value is default
for the first three rows. If N or default are missing, the defaults are
1 and NULL, respectively.

N must be a literal nonnegative integer. If N is 0, expr is evaluated
for the current row.

Beginning with MySQL 8.0.22, N cannot be NULL. In addition, it must now
be an integer in the range 0 to 263, inclusive, in any of the following
forms:

o an unsigned integer constant literal

o a positional parameter marker (?)

o a user-defined variable

o a local variable in a stored routine

over_clause is as described in
https://dev.mysql.com/doc/refman/8.0/en/window-functions-usage.html.
null_treatment is as described in the section introduction.

URL: https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html

