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 |
|
herman404
Starting Member
10 Posts |
Posted - 2006-07-29 : 10:00:47
|
| Hi everyone, I have some trouble writing a SQL stored procedure that can do the following:We have data in one table in numeric form, but we want to sum the data in this table based on the values of two different alpha fields. To illustrate, let me write the following example:Table with these records:A B 1.1 2.2 Blah1 Blah1A B 2.3 5.6 Blah2 Blah2B C 7.8 9.1 Blah3 Blah3B C 4.5 1.0 Blah4 Blah4R F 1.1 4.3 Blah5 Blah5B A 3.1 2.7 Blah6 Blah6I need to write a query that will return the following result set from the above table:A B 3.4 7.8 Blah1 Blah1B C 12.3 10.1 Blah3 Blah3R F 1.1 4.3 Blah5 Blah5B A 3.1 2.7 Blah6 Blah6If the alphanumberic keys are the same, the sum the numeric columns up whilst displaying one one of the records, the blah fields don't matter if only one is displayed. Can anyone recommend the best way to do this?I'm running MS SQL 2005.Thanks! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-29 : 10:53:48
|
| Select col1,col2,sum(col3),sum(col4),min(col5),min(col6) from yourTableGroup by col1,col2MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|