Skip to main content
Module 7 · Lesson 2 of 426/57 in the course~16 min
Module lessons (2/4)

Window Functions: Rankings and Group Calculations

Lesson preview5 hands-on exercises readySQL Course · Module 7 — Advanced Analytics

ROW_NUMBER, RANK, and DENSE_RANK with OVER (PARTITION BY ...) without collapsing rows.

What you'll learn in this lesson

  • Distinguish GROUP BY (collapses rows) from window functions OVER (...) (keep each row intact).
  • Calculate rankings within each partition with ROW_NUMBER, RANK and DENSE_RANK, mastering the management of ties.
  • Filter the top-N by group by combining a CTE outside the calculation window.

Overview

GROUP BY compresses one hundred lines into one summary line per group. But what do you do when you want to keep all the individual rows (names, prices, timestamps) alongside each one with its ranking in the category or the percentage of the total? Window Functions (OVER) are needed.

Window functions are evaluated after WHERE, GROUP BY and HAVING, but before the final ORDER BY.

Sections covered in this lesson

  1. 11. Mental Model: GROUP BY vs OVER (...) and Equal Merit
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Lab: Compare ROW_NUMBER, RANK and DENSE_RANK
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 7 — Advanced Analytics

Unlock "Window Functions: Rankings and Group Calculations" and the full SQL Course curriculum

ROW_NUMBER, RANK, and DENSE_RANK with OVER (PARTITION BY ...) without collapsing rows.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in SQL Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.