How to get the first wire_open and wire_close group in the data
P粉317679342
P粉317679342 2024-02-26 08:47:46
0
1
328

This is the data I want to output, it matches the blue line and the photo of the desired output I have attached, please take a look and use the SQL query to get the desired result

P粉317679342
P粉317679342

reply all(1)
P粉571233520

测试一下:

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 

https://www.db-fiddle.com/f/njuPYFYug87jTWKHHv6yRK/2 (感谢 @lemon 的小提琴)。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!