>Actually, there is a way to do this by taking advantage of variables. If
>you read my previous post on the matter, you can use variables to get a
>cumulative total.
>----- Original Message -----
>From: "Steve Ruby" <[EMAIL PROTECTED]>
>To: "Roger Karnouk" <[EMAIL PROTECTED]>
>Cc: <[EMAIL PROTECTED]>
>Sent: Friday, April 27, 2001 12:37 PM
>Subject: Re: Viewing data from the previous row
>
>
> > Roger Karnouk wrote:
> > >
> > > Is it possible in a Select query to get values from the previously read
>row
> > > in order to do things like cumulative sums or other formulas which
>require
> > > the previous value in order to calculate the current value.
> > >
> > > ex.
> > > day current sales cumu_total
> > > ----- ------------------- ----------------
> > > 1 120 120
> > > 2 60 180
> > > 3 125 305
> > > 4 40 345
> > >
> > > I'd like to be able to do this in one select statement
> > > is this even possible?
> > >
> > > Roger Karnouk
> > > [EMAIL PROTECTED]
Sir, the following works on my machine:
SELECT t1.period, t2.sales AS current_sales, Sum(t2.sales) AS cum_total
FROM table t1, table t2
WHERE t2. period <= t1. period
GROUP BY t1. period;
Have I ever mentioned the book 'SQL For Smarties' by Joe Celko in any
of my previous posts in this mailing list?
Bob Hall
Know thyself? Absurd direction!
Bubbles bear no introspection. -Khushhal Khan Khatak
MySQL list magic words: sql query database
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php