nth_value()

The nth value of expr in the frame. Can IGNORE or RESPECT NULLS.

Reference: DuckDB 2.0.0

Arguments & returns

nth_value(expr, n)

window
Overload link exprn Returns
#01 ANYBIGINT ANY

Example

nth_value example
SQL
Haybarn WASM 2.0.0-rc12 · In your browser

Engine example with sample data · Run to view results.

In other engines

Oraclenth_value()

SELECT NTH_VALUE(x, 2) FROM LAST OVER (ORDER BY y) AS c FROM t
In DuckDB
SELECT NTH_VALUE(x, 2) OVER (ORDER BY y) AS c FROM t

SQLGlot example ↗

Snowflakenth_value()

SELECT NTH_VALUE(is_deleted, 2) OVER (PARTITION BY id) AS nth_is_deleted FROM my_table
In DuckDB
SELECT NTH_VALUE(is_deleted, 2) OVER (PARTITION BY id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS nth_is_deleted FROM my_table

SQLGlot example ↗