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.
| 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 – Fee22007/10 Tom $20.00 $32.192007/10 Bob $10.00 $5.322007/11 Tom $18.00 $2.902009/12 Tom $30.00 $72.772009/12 Tom $40.00 $82.192009/12 Tom $3.00 $3.19I 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 – Fee22007/10 Tom 1 $20.00 $32.192007/10 Bob 1 $10.00 $5.322007/11 Tom 1 $18.00 $2.902009/12 Tom 3 $73.00 $158.15Not 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 tablegroup by Date, Name[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Shanew
Starting Member
20 Posts |
Posted - 2009-04-29 : 14:10:08
|
| Hi Khtan,Thanks for the Query, it did just what i needed!ShaneShane Weddlewww.TechKnowPros.com |
 |
|
|
|
|
|
|
|