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

LAG and LEAD Functions

Window functions that return a value from a previous row (LAG) or a following row (LEAD) within a partition.

Definition

LAG and LEAD take an offset (default 1) and a default value to return when no such row exists. They are used to compute period-over-period changes, gaps between events and session boundaries without self joins.

Example

Sales - LAG(Sales) OVER (ORDER BY Month) AS MoMChange

Exam tip

LAG looks backward and LEAD looks forward; either one replaces a self join on 'previous row'.

Related terms