;WITH cte AS
(
SELECT *,
ROW_NUMBER() OVER (PARTITION BY eventid ORDER BY timestamp DESC) AS rn
FROM yourTable
)
SELECT min(yt.timestamp) as Start_Time, max(yt.timestamp) as End_Time,yt.eventid
FROM yourTable yt
inner join cte
On cte.eventid=yt.eventid
WHERE
cte.rn = 1 and cte.active="false"
group by yt.eventid
In this way you will not see E2, because of it is still active.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…