Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stepwise addition of elements of a column?

Status
Not open for further replies.

mje397

Programmer
Nov 3, 2004
17
US
I have an access table with just one column having numbers
1 2 3 4 5 ...

Can I create another column with numbers 1,3,6,10,....( ie. Sum of numbers ) using query or any other method..

It should look like this


1 1
2 3
3 6
4 10
5 15
6 21

Thanks
 
Something like this ?
SELECT A.Number, (SELECT Sum(B.Number) FROM yourTable B WHERE B.Number<=A.Number) AS SumOfNumber
FROM yourTable A
ORDER BY A.Number;

Or this ?
SELECT A.Number, Sum(B.Number) As SumOfNumber
FROM yourTable A INNER JOIN yourTable B
ON A.Number >= B.Number
GROUP BY A.Number
ORDER BY A.Number;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Or:

Code:
SELECT A.Num2Sum, Sum(B.Num2Sum) AS RunSum
FROM tblSeqNums AS A 
INNER JOIN tblSeqNums AS B ON A.Num2Sum >= B.Num2Sum
GROUP BY A.Num2Sum;

which actually works






MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top