Skip to main content
Skip to main content

lagInFrame

Returns a value evaluated at the row that is at a specified physical offset row before the current row within the ordered frame.

Danger

lagInFrame behavior differs from the standard SQL lag window function. Clickhouse window function lagInFrame respects the window frame. To get behavior identical to the lag, use ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.

Syntax

For more detail on window function syntax see: Window Functions - Syntax.

Parameters

  • x — Column name.
  • offset — Offset to apply. (U)Int*. (Optional - 1 by default).
  • default — Value to return if calculated row exceeds the boundaries of the window frame. (Optional - default value of column type when omitted).

Returned value

  • Value evaluated at the row that is at a specified physical offset before the current row within the ordered frame.

Example

This example looks at historical data for a specific stock and uses the lagInFrame function to calculate a day-to-day delta and percentage change in the closing price of the stock.

Query:

Result: