![](/img/trans.png)
[英]Is it possible to ignore NULL values when using LAG() and LEAD() functions in SQL Server?
[英]SQL windows functions LEAD/LAG but only taking certain values into account?
您将使用lead(ignore nulls)
:
select t.*
from (select t.*,
lead(case when event <> 'install' then event end ignore nulls) over (partition by id order by timestamp) as next_event
from t
) t
where event = 'install';
ignore nulls
选项是标准的 SQL 。 但是,并非所有数据库都支持它。 此类数据库中通常还有其他选项,但没有数据库标签,建议使用标准 SQL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.