1C1A1111111 --- ---启动--- TRIP1
1C1A1111111 ---?--- --- TRIP1
1C1A1111111 ---?--- --- TRIP1
1C1A1111111 ---?--- --- TRIP1
1C1A1111111 ---?--- --- TRIP1
1C1A1111111 --- ---停止--- TRIP1
1C1A1111111 ---?------
1C1A1111111 ---?------
1C1A1111111 ---?------
1C1A1111111 ---?------
1C1A1111111 --- ---启动--- TRIP2
1C1A1111111 ---?--- --- TRIP2
1C1A1111111 ---?--- --- TRIP2
1C1A1111111 ---?--- --- TRIP2
1C1A1111111 ---?--- --- TRIP2
1C1A1111111 ---?--- --- TRIP2
1C1A1111111 ---?--- --- TRIP2
1C1A1111111 ---?--- --- TRIP2
1C1A1111111 --- ---停止--- TRIP2
答案 0 :(得分:0)
CASE -- check if current row is between start and stop
WHEN Last_Value(status IGNORE NULLS)
Over (PARTITION BY session_id
ORDER BY ts
ROWS Unbounded Preceding ) = 'start'
OR status = 'stop'
-- increase trip number whenever status = 'start'
THEN Sum(CASE WHEN status = 'start' THEN 1 END)
Over (PARTITION BY session_id
ORDER BY ts
ROWS Unbounded Preceding)
END