Ben Chuanlong Du's Blog

It is never too late to learn.

Ignore Nulls in the Analytical Window Function Lead in SQL

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

The analytical window function lead does not support ignoring NULL values. One workaround is to to use the analytical window fucntion first_value which supports ignoring NULL values.

first_value(my_col IGNORE NULLS) OVER (
  PARTITION BY pcol1, pcol2
  ORDER BY ts
  ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
)

For more discussions, please refer to Chat with Gemini: GoogleSQL Lead Ignoring NULL .

Comments