1. Learn
  2. /
  3. Courses
  4. /
  5. Data Manipulation in SQL

Connected

Exercise

Flip OVER your results

In the last exercise, the rank generated in your query was organized from smallest to largest. By adding DESC to your window function, you can create a rank sorted from largest to smallest.

SELECT 
    id,
    RANK() OVER(ORDER BY home_goal DESC) AS rank
FROM match;

Instructions

100 XP
  • Select the league name and average total goals scored from league and match.
  • Complete the window function to rank each league from highest to lowest average goals scored.
  • ORDER the main query BY the rank you just created.