Skip to main content
Module 13 · Lesson 2 of 450/57 in the course~15 min
Module lessons (2/4)

Partitioning with PARTITION BY

Lesson preview5 hands-on exercises readySQL Course · Module 13 — Window Functions

Split rows into independent analytical windows without collapsing them like GROUP BY.

What you'll learn in this lesson

  • Divide the table into independent logical windows via OVER (PARTITION BY ...) without losing the detail of the individual rows.
  • Combine group metrics (SUM, AVG, COUNT) and individual values to detect anomalies and deviations within groups.
  • Mix in the same SELECT windows with different partitions (global PARTITION BY dept and OVER ()).

Overview

A global window OVER () is useful, but in real-world contexts you want to compare each product to only products in its category, or each employee to the average budget of their department. PARTITION BY inside OVER (...) draws precisely these boundaries between groups without ever collapsing the lines.

Activate PARTITION BY dept in the stepper below with AVG: observe how the highlighted band changes dynamically, isolating only colleagues from the same department (Engineering vs Sales) when you click on different rows!

Sections covered in this lesson

  1. 11. Mental Model: Comparison GROUP BY vs PARTITION BY
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Laboratory: Colored Partition Bands
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 13 — Window Functions

Unlock "Partitioning with PARTITION BY" and the full SQL Course curriculum

Split rows into independent analytical windows without collapsing them like GROUP BY.

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.