Re: Query Question -- Query Using Monthly Data



Smitty wrote:
Hello everyone. I currently have a simple table, DAILY, containing
various daily transactions. The table has a date column, transaction
1, transaction2, transaction3 etc. Example:

DATE Transaction1 Transaction2 Transaction3
1-1-2007 5 3 1
1-13-2007 3 7 9
1-17-2007 6 2 4
2-3-2007 5 3 1
3-10-2007 5 3 1

I need to grab the data from the DAILY table, and insert the sum of
all transactions for each month into a MONTHLY table, so I will have:

DATE Transaction1 Transaction2 Transaction3
2007-01 14 12 14
2007-02 5 3 1
2007-03 5 3 1

I am very new to SQL, so I am not sure if this is simple or not.
Thanks very much in advance.

Your design is the worst possible in a relational database and violates
the rules of normalization.

A well designed table would look like this:

DATE TRANSACTION# VALUE
2007-01 1 14
2007-01 2 12
2007-01 3 14
2007-02 1 5
2007-02 2 3
2007-02 3 1
2007-03 1 5
2007-03 2 3
2007-03 3 1

With a proper design you should find writing queries far easier.
--
Daniel A. Morgan
University of Washington
damorgan@xxxxxxxxxxxxxxxx (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
.