Skip to content
SQLPro

Master SQL analytics without collapsing rows.

SQL Window Functions

Develop a precise mental model for OVER, PARTITION BY, ORDER BY, ranking, LAG and LEAD, frames, dialect differences, and performance.

What you will leave with

You can design and debug production-style window queries, including top-N per group, running totals, period comparisons, and session logic.

Modules
8
Duration
~11 hours
Level
Intermediate to Advanced
Access
Module 1 free
  • Eight animated explainers
  • Multi-dialect coverage
  • 50+ SQL challenges

What you will be able to do

What this course prepares you to do.

The curriculum is organized around these 4 practical outcomes.

Explain what each part of OVER changes

Choose the correct ranking function when ties matter

Build running, rolling, and period-comparison metrics

Control frames and translate patterns across SQL dialects

Curriculum

Every module earns the next one.

Open a module to inspect every section before you start. Your progress follows you through the course.

01
Module 1

The Mental Model: OVER, PARTITION BY, ORDER BY

IntermediateFree preview

Why window functions exist, The OVER() clause anatomy, PARTITION BY, slicing the data, and more.

View 6 sections
  1. 1Why Window Functions Exist
  2. 2Anatomy of OVER(): The Three Dials
  3. 3PARTITION BY: Many Windows, One Query
  4. 4ORDER BY in OVER: Sequence Matters
  5. 5Where Windows Run in the Pipeline
  6. 6NULLs in ORDER BY Inside OVER
85 min6 sections
Open module
02
Module 2

Ranking Functions: ROW_NUMBER, RANK, DENSE_RANK, NTILE

IntermediatePro

ROW_NUMBER, unique sequential ranks, RANK, competition ranks with gaps, DENSE_RANK, tiers without gaps, and more.

View 5 sections
  1. 1ROW_NUMBER: The Default Rank
  2. 2RANK vs DENSE_RANK: Handling Ties
  3. 3NTILE: Bucketing into Quartiles & Deciles
  4. 4Top-N Per Group: The Interview Pattern
  5. 5ROW_NUMBER for Dedup: The One Canonical Recipe
75 min5 sections
Open module
03
Module 3

Aggregate Window Functions

IntermediatePro

SUM/AVG/COUNT/MIN/MAX with OVER, Running totals, Grand totals & percent-of-total, and more.

View 6 sections
  1. 1Aggregate-as-Window: The Mental Switch
  2. 2Running Totals & Cumulative Sums
  3. 3Percent of Total & Share Analysis
  4. 4Combining Multiple Windows in One Query
  5. 5FILTER Previews & the COUNT(DISTINCT) Caveat
  6. 6Mixing Aggregates with Ranking: A Preview
85 min6 sections
Open module
04
Module 4

LAG, LEAD & Comparing Rows

IntermediatePro

LAG, look at the previous row, LEAD, look at the next row, Period-over-period growth, and more.

View 6 sections
  1. 1LAG: Looking Backward
  2. 2LEAD: Looking Forward
  3. 3Period-Over-Period Growth
  4. 4Gap Analysis & Sequence Patterns
  5. 5LAG With Offsets & The Forward-Fill Trap
  6. 6Production Pattern: Cohort Retention
80 min6 sections
Open module
05
Module 5

Frame Clauses: ROWS vs RANGE

AdvancedPro

Default frames, and why they bite, ROWS, physical row counting, RANGE, logical value counting, and more.

View 6 sections
  1. 1The Default Frame & Why It Bites
  2. 2ROWS: Counting Physical Positions
  3. 3RANGE: Counting Logical Values
  4. 4Moving Averages & Centered Frames
  5. 5EXCLUDE Clauses & Numeric RANGE BETWEEN
  6. 6The Five Mistakes Reviewers Catch in PRs
85 min6 sections
Open module
06
Module 6

Multi-Dialect Reality: SQLite vs PostgreSQL

AdvancedPro

The SQL standard vs vendor reality, PostgreSQL extensions: FILTER, IGNORE NULLS, RANGE BETWEEN INTERVAL, only in some dialects, and more.

View 6 sections
  1. 1Why Dialects Diverge
  2. 2FILTER & IGNORE NULLS: Postgres Superpowers
  3. 3NULLS FIRST / NULLS LAST: The Silent Cross-Dialect Trap
  4. 4RANGE Intervals: A PostgreSQL-Only Trick
  5. 5QUALIFY & the WHERE-on-Windows Workaround
  6. 6The Portability Decision Tree
85 min6 sections
Open module
07
Module 7

FIRST_VALUE, LAST_VALUE, NTH_VALUE & FILTER

AdvancedPro

FIRST_VALUE & LAST_VALUE, and the LAST_VALUE trap, NTH_VALUE, sampling the Nth row, PERCENT_RANK & CUME_DIST, and more.

View 7 sections
  1. 1FIRST_VALUE: Anchoring to the Start
  2. 2LAST_VALUE: And the Frame Trap
  3. 3NTH_VALUE, PERCENT_RANK, CUME_DIST
  4. 4PERCENTILE_CONT & PERCENTILE_DISC for Median & p95
  5. 5Conditional Aggregation Inside Windows
  6. 6Sessionization: The Itzik Ben-Gan Recipe
  7. 7Production Pattern: Cohort Retention Heatmap
85 min7 sections
Open module
08
Module 8

Performance & Anti-Patterns

AdvancedPro

Windows vs self-joins, when each wins, Common anti-patterns and how to spot them, EXPLAIN reading for window queries, and more.

View 5 sections
  1. 1Windows vs Self-Joins: When Each Wins
  2. 2Anti-Patterns You Will See in Production
  3. 3Reading EXPLAIN for Window Queries
  4. 4Refactoring Slow Analytics Queries
  5. 5Capstone: Every Module in One Query
80 min5 sections
Open module

Who this course is for

Built for people who need to use the skill.

Start with the background you have. The prerequisite notes above tell you exactly what is assumed.

01

Analysts moving into advanced SQL

02

Analytics engineers

03

Candidates preparing for senior SQL interviews

Start the course

Begin with The Mental Model: OVER, PARTITION BY, ORDER BY.

Module 1 introduces the language and example used throughout the rest of the course.

Open Module 1
SQL Window Functions Deep Dive - Master OVER, PARTITION BY, Ranking, Frames | Interactive Course (Module 1 Free) | Let's Data Science