sql >> Base de Datos >  >> RDS >> Oracle

Cómo obtener los valores para la próxima y próxima fecha en una tabla

Puedes usar las funciones de la ventana para ello

    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 

La salida es

NextVal NextPrice SecondVal SecondPrice
2       101       3         102