v.25.6New Feature

Support lag and lead window functions

Support lag and lead window functions. Closes #9887. #82108 (Dmitry Novik).
Added support for the lag and lead window functions in ClickHouse.

Why it matters

These functions enable accessing previous or next rows within a window frame, allowing users to perform comparisons and calculations across rows in a more efficient and expressive way.

How to use it

Use the lag and lead functions within an OVER clause in your SELECT statements to access preceding or following row values. For example:

SELECT
<columns>,
lag(<column>, <offset>, <default>) OVER (PARTITION BY ... ORDER BY ...) AS previous_value,
lead(<column>, <offset>, <default>) OVER (PARTITION BY ... ORDER BY ...) AS next_value
FROM <table>


where offset and default are optional parameters.