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 |
|
Marmot74
Starting Member
4 Posts |
Posted - 2007-02-16 : 15:25:03
|
| Table ExampleTABLE1ID Total DetailAmount1 10 51 10 52 7 32 7 22 7 23 5 5How would I SUM up TABLE1 on Total Column by Unique ID only? So basically in the Ex. the total would be 22.I cannot SUM on detail due to the SUM of details not always equaling Total. Total is the amount we want. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-16 : 16:05:32
|
| select sum(distinct total) from table1Peter LarssonHelsingborg, Sweden |
 |
|
|
Marmot74
Starting Member
4 Posts |
Posted - 2007-02-16 : 16:52:40
|
| That won't work because the Totals are not always Unique. Sorry I did not state that. So basically it could be.ID Total DetailAmount1 10 51 10 52 7 32 7 22 7 23 5 54 10 10etc. |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2007-02-16 : 18:56:54
|
| Does this fit your need?SELECT SUM(a.Total)FROM ( SELECT ID, Total FROM MyTable GROUP BY ID, Total -- DetailAmount, too? ) a=======================================If Tyranny and Oppression come to this land, it will be in the guise of fighting a foreign enemy. -James Madison, fourth US president (1751-1836) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-17 : 02:14:22
|
| SELECT SUM(Total)FROM (SELECT DISTINCT ID, Total, DetailAmount FROM Table1) AS aPeter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|