I have a table called “Status” as shown below in sql server.
How can I filter the records where the timestamp is less then 5 minutes for the same Level and same Status?
Eg: For the above records my output should be like
Advertisement
Answer
Use lag()
:
x
select s.*
from (select s.*, lag(date) over (partition by level, status order by date) as prev_date
from status s
) s
where prev_date is null or
prev_date > dateadd(minute, -5, date);