Funnily enough, this was just posted to the [EMAIL PROTECTED] list: : From: "Lord, David - CSG" <[EMAIL PROTECTED]> : Subject: RE: Sum of Previous Record : : You can use SUM as an analytic function like this: - : : SQL> select credit, debit, sum(credit + debit) over (order by rowid) from foo; : : CREDIT DEBIT SUM(CREDIT+DEBIT)OVER(ORDERBYROWID) : ---------- ---------- ----------------------------------- : 3 0 3 : 0 -1 2 : 1 0 3 : : Obviously, you will need to order by something more sensible than the rowid : (perhaps a timestamp).
Tim. On Wed, Jun 04, 2003 at 06:48:26PM +0100, Tim Bunce wrote: > There's probably a way to do that using Oracle OLAP queries in 9i. > But I'm not familar with the syntax, sorry. > > Tim. > > On Wed, Jun 04, 2003 at 08:00:17AM -0700, Dean Arnold wrote: > > A DBIx::Chart user is experiencing problems with the following query: > > > > > $rsth = $dbh->prepare( > > > "SELECT GRAINS,SUM(GRAINS) FROM SOMETABLE > > > RETURNING linegraph(*), imagemap where width=500 and > > > AND HEIGHT=500"); > > > > > > and the again the error: > > > > > > DBD::Oracle::db prepare failed: ORA-00937: not a single-group > > > group function (DBD ERROR:OCIStmtExecute/Describe) > > > for statement "SELECT GRAINS,SUM(GRAINS) FROM SOMETABLE" > > > > > > > They claim that the error does not occur when the "RETURNING > > linegraph(*)..." clause > > is removed. Alas, I don't have an Oracle instance handy to test with, but > > was > > wondering if "SELECT X, SUM(X) FROM MYTABLE" was valid > > Oracle syntax without a GROUP BY clause ? Does that compute a cumulative > > sum in Oracle ? > > > > Any insights much appreciated, > > Dean Arnold > > Presicient Corp. > >
