0

enter image description here

I could not add image

  • 1
    1) Please don't use images for data, use formatted text. 2) You are expected to show us what you have tried and explain where you are stuck. – DB08 Mar 29 '22 at 16:59
  • Presumably `with data as (select *, lead(time) over (partition by machinename order by time) as nexttime from T) select * from data where machinestate = 'Running'` – shawnt00 Mar 29 '22 at 17:50

1 Answers1

0

You can try do something like this:

Select machinestate, 
Lead(machinestate,1) OVER (PARTITION BY machinename ORDER BY time) as 
         next_machinestate, 
Lead(time,1) OVER (PARTITION BY machinename ORDER BY time) - time as 
         time_range 
from your_table