Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Using Monthly Data

Status
Not open for further replies.

marksmithy69

Programmer
Apr 20, 2001
60
0
0
CA
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.
 
It sounds very straightforward:

select to_char(date, 'YYYY-MM') as month,
sum(transaction1) as transaction1,
sum(transaction1) as transaction2,
sum(transaction1) as transaction3
from table
group by to_char(date, 'YYYY-MM')
 
...And I'm sure Dagon meant:
Code:
select to_char(date, 'YYYY-MM') as month, 
sum(transaction1) as transaction1,
sum(transaction2) as transaction2,
sum(transaction3) as transaction3
from table
group by to_char(date, 'YYYY-MM');


[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top