Cumulative Totals in Query Builder

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

Guest

I am pulling data from Oracle and performing a sum in a pass-through query.
In my second step, through Query Builder, I am trying to create a cumulative
sum of the data.

My data fields are:

YYYYMM: Year/ Month of Data (text field)
ST: State (text field)
CLDATE: Closed Date (date field)
SAVINGS: Savings (number)

Sample Data:

YYYYMM ST CLDATE SAVINGS

200601 NY 01/03/06 100
200601 NY 01/03/06 100
200601 NJ 01/03/06 100
200602 NY 01/04/06 100

I am trying to do a cumulative sum of savings by yrmo, st, and date. I have
tried many of the solutions presented through this forum, but have not been
able to make anything work. Any help would be greatly appreciated.

Thanks.
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If you mean a running sum:


SELECT YYYYMM, ST, CLDATE,
(SELECT SUM(SAVINGS) FROM table_name
WHERE ST = T.ST AND CLDATE <= T.CLDATE)
AS CummulativeSavings
FROM table_name AS T
WHERE ...

If you mean a sum per YYYYMM, ST & CLDATE:

SELECT YYYYMM, ST, CLDATE, SUM(SAVINGS) As SumOfSavings
FROM table_name AS T
WHERE ...
GROUP BY YYYYMM, ST, CLDATE

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRDQrq4echKqOuFEgEQKO0gCeNF2+FXUjK886xMe4c9V4jS3g4ncAni8j
bVkoZEER10dxWnCNiWY3Awt5
=0uQw
-----END PGP SIGNATURE-----
 

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

Back
Top