Hi Alexandru,
You can use LAG
LAG ( <expression> [, <offset> [, <default_expression>]] )
Returns value of the 'offset' rows before current row. The 'offset' should be non-negative and default is 1.
If the offset crosses boundaries of the partition 'default' value is returned. If the 'default' is not specified null value is returned.
The 'offset' and 'default' are evaluated at current row.
The output of LAG function can be non-deterministic among tie values.
select col1,col2,col3,
LAG(col2) over (partition by col1 order by col3) as lag
from T;
Regards,
Krishna Tangudu