If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Add a running sum column in a query
I am having trouble adding a column in a query which is a running
total of my records. Example: Table 1 Column 1 has a data in each row as 1, 2, 3, 4, 5. Now i want to add a column in a query which gives me the data of column 1 and column 2 should be running total as 1, 3 (1+2), 6(1+2+3), 10 (1+2+3+4). |
#2
|
|||
|
|||
Add a running sum column in a query
This can be done, if you have a way of ordering the records that will give
unique position in the order for each record. With the limited data you have given us there is no way to know the order of the records. The following would work to give you a running sum if there are no duplicate numbers in the column1. If there are duplicate numbers then you would get the same running sum for the duplicates. SELECT Column1, (SELECT Sum(Column1) FROM Table1 as T WHERE T.Column1 = Table1.Column1) as RunningSum FROM Table1 ORDER BY Column1 -- John Spencer Access MVP 2002-2005, 2007 Center for Health Program Development and Management University of Maryland Baltimore County .. wrote in message ups.com... I am having trouble adding a column in a query which is a running total of my records. Example: Table 1 Column 1 has a data in each row as 1, 2, 3, 4, 5. Now i want to add a column in a query which gives me the data of column 1 and column 2 should be running total as 1, 3 (1+2), 6(1+2+3), 10 (1+2+3+4). |
Thread Tools | |
Display Modes | |
|
|