Oracle LAG function in TD

Database

Oracle LAG function in TD

We are facing issue in converting the Oracle LAG function in the Oracle query to TD. How can we replicate the functionality of Oracle LAG function in TD?

Reference to the Oracle LAG function - http://www.techonthenet.com/oracle/functions/lag.php

Oracle SQL code using LAG function - lag(queried_mpn) OVER( ORDER BY queried_mpn)

Need to resolve it immediately as project is going live next week and this is a showstopper.

Thanks in advance

2 REPLIES
Senior Apprentice

Re: Oracle LAG function in TD

LAG/LEAD is just a short-cut:

LAG(col,x,val) OVER (ORDER BY col2)
=
COALESCE(MIN(col)
OVER (ORDER BY col2
ROWS BETWEEN x PRECEDING AND x PRECEDING)
, val)

For LEAD replace PRECEDING with FOLLOWING.

Dieter

Re: Oracle LAG function in TD

Thanks for the quick response.

I have tried using the below TD equivalent function for LAG function but the data is not matching exactly (row by row) from Oracle and TD query. Any reason why? Is there any constraint in using the above solution.