You can try the following:
Select et1.System_ID, et1.[Date] as DateDown, et2.[Date] as DateUp, DATEDIFF(s, et1.[Date], et2.[Date]) as DownForSeconds From EventTable et1 Left Join EventTable et2 On et1.System_ID = et2.System_ID and et2.[Event] = 'Up' Where et1.[Event] = 'Down' and et2.[Date] = (Select Top 1 [Date] From EventTable Where System_ID = et2.System_ID and [Date] > et1.[Date])
user474407
source share