我只想在Window函数中过滤以保留created_at is null
,这样我以前就不用WHERE
子句了。因为当我order by created_at desc
时,它将首先显示空值。
如何在此代码中添加筛选器?
select *, first_value(title) over (partition by product_id order by created_at desc) as last_title
from t2
我试试这个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
您可以将NULL值排序到末尾:
first_value(title) over (partition by product_id order by created_at desc nulls last)
请使用以下条件,
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