Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Ranking functions
Selecting n-th row
Summary

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!

Here's the example from the previous exercise – use it to write the correct answer:

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