Hi.

On Mon, Jun 18, 2001 at 02:32:13AM +0100, [EMAIL PROTECTED] wrote:
> I need some help with a query to sum data for each id and write it into a
> new table.
> 
> I have a source data table for each calendar month containing i.d.'s (not
> unique) and a value and I need to sum all the values for each i.d. for all
> months into a new table (where each i.d. will now be unique).
> 
> The only way I could see of doing it was in two or more stages?

If I read correctly, that there is currently a table for each month,
there is no reasonable singe-stage way. If you can change the source
tables, add a column to indicate the month, then create a MERGE table
definition and run an appropriate CREATE TABLE ... SELECT ... GROUP BY
query.

If not, but the number of different ids is not too large (less than
about 100.000 or so), I would create an appropriate target table
(including a column for month) and run

INSERT INTO target SELECT 1 as month, ... FROM ... GROUP BY ...

and afterwards run the CREATE TABLE ... SELECT ... GROUP BY ... I just
talked about above.

Bye,

        Benjamin.


---------------------------------------------------------------------
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

Reply via email to