Skip to content
AnalyticsPro

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 be able to do

Leave with capability, not just vocabulary.

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

Running example

A retail dataset used across every module for ranking, customer behavior, inventory, payments, and delivery analysis.

Prerequisites

SQL Fundamentals is required. SQL Mastery is recommended.

Curriculum

Every module earns the next one.

Open any module to review its exact sections. Progress and completion follow you through the course.

8 modules · ~11 hours
01
Module 1

The Mental Model: OVER, PARTITION BY, ORDER BY

IntermediateFree preview

Topics include 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

Topics include 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

Topics include 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

Topics include 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

Topics include 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

Topics include 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

Topics include 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

Topics include 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.

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.

The first module establishes 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