我有一个表,记录如下
<表类>
ID
UID
LOKACIJA
状态
TS
tbody><<tr>16520 306 1 1 31.05.2022 23:20 16521 306 1 0 23 31.05.2022 16522 306 1 1 31.05.2022二三31 16523 306 1 0 31.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