Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help writing a query

Author  Topic 

natg504
Starting Member

14 Posts

Posted - 2011-04-01 : 12:01:28
I have a table with data in the following format:

DateRecorded __ CategoryID __ Value
January 2010 ---- 1 ----------- 5
January 2010 ---- 2 ----------- 10
January 2010 ---- 3 ----------- 15
February 2010 --- 1 ----------- 20
February 2010 --- 2 ----------- 25
February 2010 --- 3 ----------- 30
March 2010 ------ 1 ----------- 35
March 2010 ------ 2 ----------- 40
March 2010 ------ 3 ----------- 45

Is there any way that I can do a single SQL query to sum the values for each month, so it would return something like this?

DateRecorded __ Summed Value
January 2010 ------- 30
February 2010 ------ 75
March 2010 --------- 120

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-04-01 : 12:02:36
select DateRecorded , sum(value) as value from table
group by DateRecorded

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

natg504
Starting Member

14 Posts

Posted - 2011-04-01 : 12:27:05
Thanks, that is what I was looking for.
Go to Top of Page
   

- Advertisement -