N
N
newvasyuki2021-01-29 11:17:43
SQL
newvasyuki, 2021-01-29 11:17:43

How to solve this problem in SQL: find the maximum window between events?

There is a table in which events are recorded, respectively, there is a field with the time of the event. How to find the maximum window between adjacent events? Those. where before. event time record - next. record time is the longest in minutes? (datediff(string_field, next_string_field))? The primary keys of the rows are inconsistently incremented.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fallenyasha, 2021-01-29
@Fallenyasha

Look towards the window functions LEAD and LAG

SELECT max(datediff(date_value, (lead(date_value) over (order by date_value))))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question