Click to See Complete Forum and Search --> : SQL -Sum function


itrat
04-21-2006, 04:21 AM
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.. :confused:

davey23uk
04-21-2006, 05:52 AM
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

itrat
04-21-2006, 09:26 AM
Yes i need to add value from B to other value from A.
But how will adding a column help me ..
Plz help... :confused:

davey23uk
04-21-2006, 09:55 AM
how do you know which other row you want to get - what is your criteria

tamilselvan
04-21-2006, 10:30 PM
Use analytic function lead to access next row.

Tamil

DaPi
04-22-2006, 04:19 AM
Yes, but you MUST have an ORDER BY as Davey was insisting.

Itrat, how do you want to order the rows?