Skip to content
Advertisement

how to use first_value with reset

I am trying to obtain an aggregated result that appears like this:

start_time end_time task_state
‘2021-10-09 23:58:34.000 2021-10-10 00:00:25.000′ task_completed
‘2021-10-10 00:00:26.000 2021-10-10 00:01:00.000′ task_not_completed
‘2021-10-10 00:01:01.000 2021-10-10 00:01:15.000′ task_completed

I have tried using the first_value function but it just seems to give the value ‘2021-10-09 23:58:34.000’ for all the task_state.

Not sure what I am doing wrong. Here is what I tried:

looking for help for this

Advertisement

Answer

its a gaps & island problem:

db<>fiddle here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement