thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Intermediate

Window Function

A function that computes a value across a set of rows related to the current row, defined with OVER(), without collapsing them.

Definition

OVER() takes optional PARTITION BY (groups), ORDER BY (sequence) and a frame clause (ROWS or RANGE BETWEEN). Window functions include ranking (ROW_NUMBER, RANK), offset (LAG, LEAD), aggregate (running SUM, moving AVG) and distribution functions (NTILE, PERCENT_RANK).

Example

SELECT OrderDate, Sales, SUM(Sales) OVER (ORDER BY OrderDate) AS RunningTotal FROM DailySales;

Exam tip

Window functions keep every row while GROUP BY collapses rows. Window results cannot be filtered in WHERE; use QUALIFY or a subquery.

Related terms