MySQL:基于状态的两个日期之间的差异



我有一个表,记录如下

<表类> ID UID LOKACIJA 状态 TS tbody><<tr>165203061131.05.2022 23:20165213061023 31.05.2022165223061131.05.2022二三31165233061031.05.2022二三35
select timestampdiff(minute,t1.ts,t2.ts) tdiff from
(select row_number() over (order by null) rn,ts from table_1 where status=1) t1 inner join
(select row_number() over (order by null) rn, ts from table_1 where status=0) t2
where t1.rn=t2.rn

这里小提琴

添加,另一个变体-

select * from (
select timestampdiff(minute,ts,
lead(case when status=0 then ts end) over (order by null)
) ts                     
from table_1)t
where t.ts is not null

最新更新