我有一个如下所示的数据框,其中包含列: ID, STATE and TIMESTAMP . Dataframe按 ID and TIMESTAMP . 我们需要找出两者之间的时间间隔 state S1 to S2 .注意:对于一个特定的id,我们可以在s1到s2之间有多个转换。状态总是以s1开始,以s2结束。有关详细信息,请参阅所附图片:输入为蓝色,预期输出为绿色
ID, STATE and TIMESTAMP
ID and TIMESTAMP
state S1 to S2
pdtvr36n1#
select id, unix_timestamp(timestamp) - unix_timestamp(lag(timestamp) over(partition by id order by timestamp)) as time_diff from table;
1条答案
按热度按时间pdtvr36n1#