WITH
cte AS (
SELECT *, SUM(delay_ping_type = 'wire_close') OVER (ORDER BY last_updated_on DESC) group_no
FROM source_table
)
SELECT MIN(last_updated_on) wire_open,
MAX(last_updated_on) wire_close
FROM cte
-- WHERE group_no > 0 -- removes final open without close
GROUP BY group_no
-- HAVING wire_open
测试一下: