这就是我想要输出的数据,它与蓝线以及我附加的所需输出照片相匹配,请查看并使用 SQL 查询获得所需的结果
P粉5712335202024-02-27 07:08:07
测试一下:
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 < wire_close -- removes close without matched open -- HAVING MIN(last_updated_on) < MAX(last_updated_on) -- the same for PostgreSQL ;
https://www.db-fiddle.com/f/njuPYFYug87jTWKHHv6yRK/2 (感谢 @lemon 的小提琴)。