Results 1 to 3 of 3

Thread: qry reg LAG

  1. #1
    Join Date
    Feb 2004
    Location
    Chennai
    Posts
    53

    Unanswered: qry reg LAG

    how can i get 2 or more colums of the previous record using the lag function

    ie, any other equivalent for the below..... hope the below one is not efficient..not even sure wheather it works... pls suggest a way

    select lag(a,1) over (order by c,d) prev_a, lag(b,1) over (order by c,d) prev_b from ....


    the order by remains the same...
    -Mathan
    For a quick pocket reference of oracle refer http://pocketoracle.blogspot.com/

  2. #2
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    Not sure what you really mean, but I guess somethi ng like this: you want to get the 2 previous values with respect to the current row. If that is, I think LAG is not what you are you looking for, since it doesn't support a Windowing clause, but any of the analytic aggregates functions. You can especify the range or rows with respect to the current row with these. More over, would be evern better if you post a test case of what you are want to achieve!

  3. #3
    Join Date
    Jul 2003
    Posts
    2,296
    Quote Originally Posted by getmathan
    how can i get 2 or more colums of the previous record using the lag function

    select lag(a,1) over (order by c,d) prev_a, lag(b,1) over (order by c,d) prev_b from ....
    that is how you would do it.
    - The_Duck
    you can lead someone to something but they will never learn anything ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •