Ask Your Question
0

BASE - Column in query as cumulative value

asked 2016-07-27 20:01:57 +0200

Alb58 gravatar image

I am lacking in SQL programming knowledge and would like to know how to generate a query which adds up the values of the previous rows. For example the first column would be something like grade school levels from 1st grade to 6th grade. The second column is number of students enrolled in that grade. These two columns are in a table. The third column which is the one I'm having trouble with is how many students in 1st grade, followed in the next row by how many students enrolled in 1st and 2nd grade, the third row adds all students from 1st to 3rd grade, etc. I want to generate a query that has all three of these columns. Any help will be appreciated.

edit retag flag offensive close merge delete

Comments

Your question has a number of contradictions. Your final statement specifies three columns but the explanation has five and mixes in ROWS. Could you please edit your original question showing what result you are looking for?

Ratslinger gravatar imageRatslinger ( 2016-07-27 20:40:45 +0200 )edit

Sorry that I wasn't clear. I tried to edit but don't find how. Here's an example of what I'd like. I have a table with the first 2 columns. I want to make a query that will add the third one w/ cumulative amounts. |Grade | Number of Students | Cumulative Number of Students | |1st Grade | 5 | 5 | |2nd Grade | 7 | 12 | |3rd Grade | 6 | 18 | |4th Grade | 5 | 23 |

Alb58 gravatar imageAlb58 ( 2016-07-27 22:14:47 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2016-07-28 00:53:27 +0200

Ratslinger gravatar image

There is most likely a better way to accomplish what you want, but this works:

image description

The UNION statements create total records which are joined to the original selection records. Obviously, the GRADENUMBER values are the critical part. The table in the upper right corner represents the table you already have.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-07-27 20:01:57 +0200

Seen: 119 times

Last updated: Jul 28 '16