比较oracle sql中的当前行和上一行

比较oracle sql中的当前行和上一行,sql,oracle,Sql,Oracle,我需要比较当前行和前一行,并根据一些比较需要导出一个列值。目前,我所遵循的方法是制作两个不同的记录集,然后使用秩函数,然后通过加入秩函数,我能够实现这一点。然而,这似乎是乏味的,有没有更好的方法来实现这一点。我目前正在写以下内容: select < comparing columns from two record sets and deriving column value> ( select(<some complex

我需要比较当前行和前一行,并根据一些比较需要导出一个列值。目前,我所遵循的方法是制作两个不同的记录集,然后使用秩函数,然后通过加入秩函数,我能够实现这一点。然而,这似乎是乏味的,有没有更好的方法来实现这一点。我目前正在写以下内容:

    select 
< comparing columns from two record sets and deriving column value> 
              (
        select(<some complex logic>, rank from a) rcdset, 
    (select <some complex logic>, rank +1 from a) rcdset2 where rcdset.rnk = rcdset1.rnk (+)
数据库-Oracle 10g

使用LAGvalue\u expr OVER ORDER BY rank\u col从rank\u col定义的上一行顺序检索值expr,请参见使用分析函数LAG/LEAD。