1

I only want to filter in Window function to keep the created_at is null so I don't use WHERE clause previously. Because when I order by created_at desc it will show the null value first.

How to add a filter in this code?

select *, first_value(title) over (partition by product_id order by created_at desc)  as last_title
from t2

I try this not work:

select *, first_value(title) over (partition by product_id order by created_at desc) having (created_at is not null) as last_title
    from t2

2 Answers 2

4

You can sort the NULL values to the end:

first_value(title) over (partition by product_id order by created_at desc nulls last)
Sign up to request clarification or add additional context in comments.

Comments

0

Please use below condition,

select *, first_value(title) over (partition by product_id order by created_at desc)  
as last_title
from t2 where created_at is not null

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.