DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Getiing delta between rows through SQL

  1. #1
    Join Date
    Feb 2000
    Location
    Singapore
    Posts
    1,758

    Getiing delta between rows through SQL

    Oracle 8.1.7.0

    I have a requirement to ge the delta between rows. For example;
    Code:
    Column1   Delta
    -------   ------
    10        10
    15        05
    17        02
    20        03
    25        05
    30        05
    40        10
    The column1 value is cumulative and it goes on increasing. I have to get delta between the rows. Is there any way I can do it using SQL.
    TIA
    Sanjay G.
    Oracle Certified Professional 8i, 9i.

    "The degree of normality in a database is inversely proportional to that of its DBA"

  2. #2
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    not sure if this is what you are looking for

    Code:
    SQL> select sal, leadsal, (leadsal - sal) delta
      2  from (select sal, lead(sal, 1) over (order by empno) leadsal
      3        from emp);
    
           SAL    LEADSAL      DELTA
    ---------- ---------- ----------
           800       1600        800
          1600       1250       -350
          1250       2975       1725
          2975       1250      -1725
          1250       2850       1600
          2850       2450       -400
          2450       3000        550
          3000       5000       2000
          5000       1500      -3500
          1500       1100       -400
          1100        950       -150
           950       3000       2050
          3000       1300      -1700
          1300

  3. #3
    Join Date
    Feb 2000
    Location
    Singapore
    Posts
    1,758
    Thanks much Pando,

    This is exactly what I was looking for.
    Sanjay G.
    Oracle Certified Professional 8i, 9i.

    "The degree of normality in a database is inversely proportional to that of its DBA"

Posting Permissions

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


Click Here to Expand Forum to Full Width