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 |
|
pamschle
Starting Member
2 Posts |
Posted - 2005-10-11 : 20:51:04
|
| Need help building a SQL statement that will return the SUM of colB from a database table for unique values of colA.For instance:select DISTINCT colA, SUM(colB) from tableADoesn't work, but it's the right idea.Any help would be appreciated.Thanks - Paula |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-10-11 : 20:57:35
|
| You don't want DISTINCT, but rather GROUP BY -- read up on it in books on-line or in a decent beginning SQL book. It is a very powerful feature.SELECT ColA, SUM(ColB)FROM TableAGROUP BY ColA |
 |
|
|
Hippi
Yak Posting Veteran
63 Posts |
Posted - 2005-10-11 : 20:59:30
|
How aboutselect colA, sum(colB) from Tablegroup by colAHippi |
 |
|
|
pamschle
Starting Member
2 Posts |
Posted - 2005-10-12 : 09:02:00
|
| That suggestion returns all the distinct rows, I only want to return the sum - result set should be one row, one column.Thanks! Paula |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-10-12 : 09:06:12
|
| can you post some data .. how you want ???Complicated things can be done by simple thinking |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-10-12 : 09:12:29
|
| select sum(colb) from table |
 |
|
|
|
|
|