If you’re getting an error that reads “The function ‘LAG’ must have an OVER clause” in SQL Server, it’s probably because you’re calling the LAG()
function without an OVER
clause.
The LAG()
function requires an OVER
clause (and that clause must have an ORDER BY
clause).
To fix this issue, be sure to include an OVER
clause when calling the LAG()
function.