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_idvalue_1actionnext_timetimestamp ,
110000881011544912020-06-01 08:29:30.382 UTC2020-06-01 08:29:25.540 UTC
11000088101154491null2020-06-01 08:29:30.382 UTC
posted @ 2022-08-19 22:51  luoganttcc  阅读(6)  评论(0)    收藏  举报