Back to Developer Roadmap

lag

src/data/roadmaps/sql/content/[email protected]

4.0785 B
Original Source

lag

LAG is a window function in SQL that provides access to a row at a specified offset prior to the current row within a partition. It allows you to compare the current row's values with previous rows' values without using self-joins. LAG is particularly useful for calculating running differences, identifying trends, or comparing sequential data points in time-series analysis. The function takes the column to offset, the number of rows to offset (default is 1), and an optional default value to return when the offset goes beyond the partition's boundary.

Visit the following resources to learn more: