SQL 通信间隔时间

SQL time between communication

大家好希望你们都平安,

我在 SQL 中有一个带有时间戳的 table,我想在我订购它们后计算两次通信之间的时间 DEC

我到处都找过了,但不幸的是没有成功:( 理想的结果应该与黄色列相同

提前致谢!

您可以使用 lag() 获得差异:

select t.*,
       (timestamp - lag(timestamp, 1, timestamp) over (order by timestamp)) diff_interval
from t;

我不知道将间隔转换为分钟是否是您问题的重要组成部分。

如果秒精度足够,可以使用:

select t.*,
       (timestamp - lag(timestamp, 1, timestamp) over (order by timestamp)),
       extract(epoch from (timestamp - lag(timestamp, 1, timestamp) over (order by timestamp))) / 60.0 as minutes
from t;