Brainlag
  1. SQL
  2. Advanced
23/39 lessons

Window functions, ranking rows

35 min6 exercisesPremium

Rank rows with ROW_NUMBER, RANK and DENSE_RANK over a window, use PARTITION BY for a ranking per group, and find each player's best session.

The skill
Rank rows within groups and pick the top one or two of each.
You make
Leaderboards for a game launcher: best sessions, top games per genre, newest players.

Premium lesson

£7.99 a month or £59 a year. Cancel any time.

Builds on 22 UNION, stacking two results. Free to try: SQL Foundations and the playground.

Step 1 of 9
exercise_1.sql

You've reached the good stuff.

6 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.

SQLite