sql lead
WITH data AS
(SELECT 1000088101 as player_id, 15449 as value_1, 1 as action,'2020-06-01 08:29:25.540 UTC' as timestamp
UNION ALL SELECT 1000088101, 15449, 1,'2020-06-01 08:29:30.382 UTC'
)
select player_id, value_1, action, LEAD(timestamp,1) OVER (PARTITION BY player_id ORDER BY timestamp ASC) next_time, timestamp,
from data
就是将数据顺序相连,便于计算时间差,如图可见 ,该用户有两条数据,将下一条数据,放到当前
| 行 | player_id | value_1 | action | next_time | timestamp , |
|---|---|---|---|---|---|
| 1 | 1000088101 | 15449 | 1 | 2020-06-01 08:29:30.382 UTC | 2020-06-01 08:29:25.540 UTC |
| 1 | 1000088101 | 15449 | 1 | null | 2020-06-01 08:29:30.382 UTC |

浙公网安备 33010602011771号