Introduction
Ranking functions
Selecting n-th row
Revision

Instruction

Very good! You may wonder if you can use regular ORDER BY with the ranking functions. Of course, you can. The ranking function and the external ORDER BY are independent. The ranking function returns the rank with the respect to the order provided within OVER.

Let's look at the example:

SELECT
  name,
  RANK() OVER (ORDER BY editor_rating)
FROM game
ORDER BY size DESC;

The query returns the name of the game and the rank of the game with respect to editor ranking. The returned rows are ordered by size of the game in descending way.

Exercise

For each game find its name, genre, its rank by size. Order the games by date of release with newest games coming first.

Console

Code editor

Result

TableConsole