AI engineering glossary · SQL databases

What is LAG (LAG and LEAD)?

LAG and LEAD (also called LAG, LEAD): Window functions that read a value from an earlier row (LAG) or a later row (LEAD) in the ordered partition, without a self join. They are used for changes between consecutive rows.

Level: intermediateTopic: SQL databases

LAG and LEAD: an example

amount - LAG(amount) OVER (ORDER BY month) gives month-on-month change in sales.

Related terms

More SQL databases terms

Where you learn it

LAG and LEAD is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.