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

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

Let's look at an example:

SELECT
  Name,
  RANK() OVER (ORDER BY EditorRating ASC) AS Ranking
FROM Game
ORDER BY Size DESC;

This query returns each game's name and rank (based on its editor ranting). The returned rows are in descending order based on the size of the game.

Exercise

Find each game's name, genre, and its rank by size. Name the column Ranking. Then order the games by release date with the newest games coming first.