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

Thread: SQL -Sum function

  1. #1
    Join Date
    Apr 2006
    Posts
    4

    SQL -Sum function

    Hi,
    Table
    A B---------------------------COLUMN
    A1 B1
    A2 B2
    A3 B3
    A4 B4
    ....
    I need the sum of data in column A and column B such that
    A B SUM---------------------------COLUMN
    A1 B1 A2+B1
    A2 B2 A3+B2
    A3 B3 A4+B3
    A4 B4 A5+ B4 ...
    Please help..

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    your requirement isnt clear, you want to sum up the value of b from one row and a from the next row?

    If so that aint possible as rows dont have an order in heap tables. you will need to use additional column to get what you want

  3. #3
    Join Date
    Apr 2006
    Posts
    4
    Yes i need to add value from B to other value from A.
    But how will adding a column help me ..
    Plz help...

  4. #4
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    how do you know which other row you want to get - what is your criteria

  5. #5
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Use analytic function lead to access next row.

    Tamil

  6. #6
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    Yes, but you MUST have an ORDER BY as Davey was insisting.

    Itrat, how do you want to order the rows?
    "The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous" - Gibbon, quoted by R.P.Feynman

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