我想从这个 table 计算机器模式时间范围。我如何为这种情况编写 SQL 查询?

I want to calculate machine mode time range from this table. How can I write a SQL query for this situation?

enter image description here

我无法添加图片

您可以尝试这样做:

Select machinestate, 
Lead(machinestate,1) OVER (PARTITION BY machinename ORDER BY time) as 
         next_machinestate, 
Lead(time,1) OVER (PARTITION BY machinename ORDER BY time) - time as 
         time_range 
from your_table