FROM test1 a,(SELECT @startTime := '') AS b,(SELECT @floor :=0) AS c,(SELECT @index :=0) AS d WHERE 1
ORDER BY t_time
) t GROUP BY t.floor_index
x66
2019-08-06 14:17:11 +08:00
row_number 根据 t_time 排序,然后自连接 a.row_number = b.row_number +1 ,然后 group by floor,求差再求和就好了
zhuanggu
2019-08-06 19:59:17 +08:00
select floor ,sum(next_time-t_time) as ts from ( select floor ,t_time ,lead(t_time,1) over(partition by floor order by t_time ) as next_time from tablename ) t group by floor;