简体   繁体   中英

comparing current row and previous in oracle sql

I need to compare current row and previous row and based on some comparision need to derive a column value. Currently apporach I m following is making two differnt record sets and then use rank function and then by joining rank functions I m able to achiieve this. However, this seems to be tedious apporach, is there a better way to achieve this. I m currently writing query something like below :-

    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 (+)

Database - Oracle 10g

使用LAG(value_expr) OVER (ORDER BY rank_col) )从上一行(由rank_col定义的顺序LAG(value_expr) OVER (ORDER BY rank_col)中检索值(value_expr),请参见http://oracle-base.com/articles/misc/lag-lead-analytic-functions .PHP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM