cumulative sum in a query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to calculate a cumulative sum in a query. For example if the query has
a field with the following data:
1
2
3
4

then the result should be:
1
3
6
10

Could you help me?
 
rpt said:
I need to calculate a cumulative sum in a query. For example if the query has
a field with the following data:
1
2
3
4

then the result should be:
1
3
6
10


The need for this kind of thing is fairly rare. Since,
a) you should normally not display the results of a query
directly to users, b) this kind of calculation should be
done in a report instead of its query, and c) a data entry
form has very little need to display this kind of value.

Anyway, to answer the question:

SELECT T.field,
(SELECT Sum(X.field)
FROM table As X
WHERE X.field <= T.field
) As result
FROM table As T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top