Alright. We'll start with the most widely used ranking function:
RANK(). The syntax is as follows:
RANK() OVER (ORDER BY ...)
RANK() do? It returns the rank of each row as a number. This rank is determined by the sorting criteria specified within the
RANK() statement's brackets.
ORDER BY sorts rows and displays them in a specific order.
RANK() OVER(ORDER BY ...) is a function that shows the rank (i.e. place or position) of each row in a separate column.
Let's look at an example from our database:
RANK() OVER(ORDER BY EditorRating ASC) AS Ranking
The first three columns are quite obvious, but look what happens next: we want to return the
RANK() of each row when we sort them by the column
EditorRating in (
OVER(ORDER BY EditorRating ASC)).