Introduction
Ranking functions
Selecting n-th row
Revision

Instruction

Great. As you can see, ROW_NUMBER() gives a unique rank number to each row. Even those rows which share the same editor_rating value got different ranks that are expressed as consecutive numbers.

The only problem is with the order of these consecutive numbers. You could ask yourself – how does my database determine which of the games with editor_rating = 4 gets 1, 2 or 3 as the rank? The answer is – it doesn't, really. The order is nondeterministic. When you execute ROW_NUMBER(), you never really know what the output will be.

Now, how about an exercise for you?

Exercise

Use ROW_NUMBER() and for each game, show their name, date of release and the rank based on the date of release.

Stuck? Here's a hint!

Use the previous example to help you:

SELECT
  name,
  platform,
  editor_rating,
  ROW_NUMBER() OVER(ORDER BY editor_rating)
FROM game;

Console

Code editor

Result

TableConsole