When using window functions such as RANK()
in SQL Server, we must provide an OVER
clause clause with an ORDER BY
clause.
If you’re getting an error that reads “The function ‘RANK’ must have an OVER clause with ORDER BY”, it’s probably because you’re including an OVER
clause with the RANK()
function (as is required), but you’re omitting the ORDER BY
clause.
To fix this error, add an ORDER BY
clause to the OVER
clause.