Oracle
 sql >> Database >  >> RDS >> Oracle

Come ottenere i valori per la data successiva e successiva in una tabella

Puoi usare le funzioni della finestra per esso

    select  
    lead(CVal, 1) over(order by Effective_Date) as NextVal 
    ,lead(CPrice, 1) over(order by Effective_Date) as NextPrice  
    ,lead(CVal, 2) over(order by Effective_Date) as SecondVal 
    ,lead(CPrice, 2) over(order by Effective_Date) as SecondPrice

    from tbl where Effective_Date >=  '31-DEC-19'
    where rownum = 1
    order by Effective_Date 

L'output è

NextVal NextPrice SecondVal SecondPrice
2       101       3         102