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)
 SUM on groups

Author  Topic 

cornall
Posting Yak Master

148 Posts

Posted - 2009-04-07 : 10:43:40
Hi,

If I have a table

group cost
1 3
1 5
1 1
2 7
2 6
2 2

How do I get the result

group cost
1 9
2 15

cornall
Posting Yak Master

148 Posts

Posted - 2009-04-07 : 10:45:05
ignore this I was just missing a clause from my group by!
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-04-07 : 10:45:20
select Group, sum(cost) group by group

<><><><><><><><><><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-04-07 : 10:45:23
select [group], sum(cost) from table group by [group]
Go to Top of Page

cornall
Posting Yak Master

148 Posts

Posted - 2009-04-07 : 10:51:11
Cheers,

The actual query is much more complex and I was just missing one element of my group by I thought I was going mad!! LOL

Thanks for the help though.

Dave
Go to Top of Page
   

- Advertisement -