Advanced · Lesson 1 of 18

Introduction to Window Functions

Window functions calculate across related rows WITHOUT collapsing them like GROUP BY.

Add row numbers:

SELECT first_name, salary,
       ROW_NUMBER() OVER (ORDER BY salary DESC) as rank
FROM employees;

Key difference from GROUP BY:

  • GROUP BY collapses rows into groups
  • Window functions keep ALL rows, adding computed columns

The OVER() clause defines the "window" of rows.

Check your understanding

Add a row number to each employee, ordered by salary (highest first).

Examples run on the employees sample database. Open any of them in the playground to experiment.