您可以lag()
用来访问给定分区中的“上一个”行:
select
t.*,
lag(timestamp) over(partition by sr_no order by timestamp) as lag_timestamp
from mytable t
假设您想要两个时间戳之间的秒数差异,然后:
select
t.*,
unix_timestamp(timestamp)
- unix_timestamp(lag(timestamp) over(partition by sr_no order by timestamp))
as diff_seconds
from mytable t
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句