两连续行之间的时差

0 oracle

我需要简单的 SQL 来计算两个连续行之间的时间差异,任何人都可以提供帮助

在此处输入图片说明

a_h*_*ame 5

您可以使用窗口函数(又名“分析函数”)访问“当前”行之外的行中的值。

如果这样做,则必须指定一个标准来定义行的排序顺序,否则就不会有“前几行”这样的东西。

鉴于您向我们展示的信息极其有限,您可能正在寻找以下内容:

select subno,
       contrno, orderby, prepost_paid, 
       time_stamp, 
       lag(time_stamp) over (order by time_stamp) - time_stamp as timestamp_diff
from the_table
order by time_stamp;
Run Code Online (Sandbox Code Playgroud)