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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Group Group and SUM Query?

Author  Topic 

Shanew
Starting Member

20 Posts

Posted - 2009-04-28 : 22:27:59
Hello,

I have a table that I need to query, and I’m not so sure how to write it.

My table looks like this:
Date – Name – Fee1 – Fee2
2007/10 Tom $20.00 $32.19
2007/10 Bob $10.00 $5.32
2007/11 Tom $18.00 $2.90
2009/12 Tom $30.00 $72.77
2009/12 Tom $40.00 $82.19
2009/12 Tom $3.00 $3.19

I need to group by date, and then name, if the name and the date are the same I need to have count. Fee1 and Fee2 need to be summed with in the grouping. So my output would look like this.

Date – Name - Count – Fee1 – Fee2
2007/10 Tom 1 $20.00 $32.19
2007/10 Bob 1 $10.00 $5.32
2007/11 Tom 1 $18.00 $2.90
2009/12 Tom 3 $73.00 $158.15

Not sure of how to write a query that will group and Sum like this, thanks for any help!
Shane

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-04-28 : 22:37:02
[code]
select Date, Name, Count = count(*), Fee1 = sum(Fee1), Fee2 = sum(Fee2)
from table
group by Date, Name
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Shanew
Starting Member

20 Posts

Posted - 2009-04-29 : 14:10:08
Hi Khtan,

Thanks for the Query, it did just what i needed!

Shane

Shane Weddle
www.TechKnowPros.com
Go to Top of Page
   

- Advertisement -