On Fri, 2 Mar 2001, Nathan Clemons wrote:
>
> Can't you do something with SUM() to get the results, possibly in
> coordination with GROUP BY?
>
> --Nathan
>
Not to my knowledge/imagination. What are you going to group by? You want and
incremental grouping or better you want a dynamic calculation on a very specific
subset of the rows (0->current_row) while current_row inrcrements through the result.
This cannot be done in a query and probably not in SQL at all.
I can only imagine this as a loop in a higher level language (take your pick:
perl/php/C). I would start thinking of creating a temporary table with
Id,Month,Sum(sales) and from there getting the runnning sales (the Id would range from
1->12).
dummy_code follows:
for(curr_count=1;curr_count<=12;curr_count++){
pose_query("select curr_count,sum(sales_per_month) from temp_table where
id<=curr_count");
}
Maybe I'm too tired to see straight and the answer is looking at me straight in the
face but that was my $0.02 anyhow.
regards,
thalis
> On 2001.03.01 23:49:28 -0500 Thalis A. Kalfigopoulos wrote:
> > Now that I notice more closely the numbers, my answer was obviously wrong
> > with regard to the 3rd column :o)
> >
> > Very interesting question...but I doubt there is a SQL way to do that.
> > Looking fwd to what the rest will sugest.
> >
> > cheers,
> > thalis
> >
> >
> > On Fri, 2 Mar 2001, Richard Vibert wrote:
> >
> > > Hi,
> > > At 01:52 pm 2/03/2001, Thalis A. Kalfigopoulos wrote:
> > > >On Fri, 2 Mar 2001, Richard Vibert wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I having trouble working out how to get a result set similar to the
> > > > > following where I select from a table with Date & Sales column.
> > > > >
> > > > > My specific question is can I have a column that accumulates
> > values, if so
> > > > > could I have some guidance on how to express this in a select
> > statement
> > > > please.
> > > > >
> > > > >
> > > > > +----------+-----------+-----------+
> > > > > | Month | Sales | Cum Sales |
> > > > > +----------+-----------+-----------+
> > > > > | Jan | 1000 | 1000 |
> > > > > | Feb | 1500 | 2500 |
> > > > > | Mar | 1200 | 3700 |
> > > > > | April | 1400 | 5100 |
> > > > > +----------+-----------+-----------+
> > > > >
> > > > > Many thanks in advance.
> > > > >
> > > > > Richard
> > > >
> > > >I assume the query should be like:
> > > >
> > > >select MONTHNAME(date_col) as Month,count(sales_amount) as
> > > >Sales,sum(sales_amount) as Cum_sales from lala_table group by
> > > >MONTHNAME(date_col);
> > > >
> > > >regards,
> > > >thalis
> > >
> > > Thanks for your reply.
> > >
> > > This is not quite what I'm after. Count(sales) gives me the number of
> > sales
> > > transactions.
> > >
> > > The first two cols I write as monthname(date_col) as Month, sum(sales)
> > as Sales
> > >
> > > It's the next column that's got me. That needs to be a "Running total"
> > if
> > > you like.
> > >
> > > Richard
> > > =======================================
> > > Richard Vibert
> > > [EMAIL PROTECTED]
> > > Tatura Mitre10
> > > =======================================
> > >
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
> >
> --
> Nathan Clemons <[EMAIL PROTECTED]> 978-635-5300 ext 123
> Linux Systems Administrator IRC: etrnl ICQ: 2810688 AIM: StormeRidr
> O | S | D | N, 50 Nagog Park, Acton, MA 01720
> http://www.osdn.com/ Open Source Development Network
> Nextel: 978-423-0165 [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
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