Selection Values From 2 Different Rows Of Same Query For Further Calculations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nihal123
    New Member
    • May 2007
    • 1

    Selection Values From 2 Different Rows Of Same Query For Further Calculations

    COSIDER THE DATA

    Year Grade TOT SAL
    --------- -------------- ---------- -
    SAM G dIAS
    -------------------------------------
    2003 X1 2964.00 3041.08

    2004 SS 4125.00 4291.67
    2005 SS 4275.00 4441.67
    2006 SS 4725.00 4891.67
    2007 SS 6664.00 7289.0
    2008 SS 7339.00 7964.00
    --------- -------------- ---------- -
    LISA G dIAS
    -------------------------------------
    2003 X1 2964.00 3041.08

    2004 SS 4125.00 4291.67
    2005 SS 4275.00 4441.67
    2006 SS 4725.00 4891.67
    2007 SS 6664.00 7289.0
    2008 SS 7339.00 7964.00
    --------- -------------- ---------- -
    ANNA dIAS
    -------------------------------------
    2003 X1 2964.00 3041.08

    2004 SS 4125.00 4291.67
    2005 SS 4275.00 4441.67
    2006 SS 4725.00 4891.67
    2007 SS 6664.00 7289.0
    2008 SS 7339.00 7964.00

    IS RESULT FROM THE 1 QUERY QUERY
    NO I WANT THE DIFFERENCE BETWEEN SAL OF 2007 AND 2008 HOW TO DO?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Since u have put a question in article section i am moving it to oracle forum.

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      Post the SQL of the query you are currently using to retrieve this data.

      Comment

      • febyfelix
        New Member
        • May 2007
        • 9

        #4
        HOPE IT WORKS....

        SELECT T1.YEAR,T1.GREA DE,T1.SAL,
        LAG(T1.SAL,1) OVER (ORDER BY YEAR) PREV_SAL,
        T1.SAL-( LAG(T1.SAL,1) OVER (ORDER BY YEAR) ) SAL_DIFRNCE
        FROM T1 WHERE T1.YEAR=2008

        do post if any doubt is there....

        Comment

        Working...