如何获得给定时间段的最小值

How to get the minimum value for a given time-period

我有一个 table 设备故障和解决日期。在解决故障之前,每天的条目都将显示为失败。问题解决后,数据将从下一个故障日期开始。下面是一个例子

我想要一个输出,它会给我每个已解决时间戳的第一次失败时间,例如

我尝试在已解决的时间戳和失败日期之间进行左连接并取最小值,但这不起作用。

考虑以下方法

select type, 
  max(timestamp) resolved_timestamp,
  min(timestamp) first_failure_timestamp
from (  
  select *, countif(status='resolved') over win as grp
  from your_table
  window win as (partition by type order by timestamp rows between unbounded preceding and 1 preceding)
)
group by type, grp    

如果应用于我们问题中的样本数据 - 输出是