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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-09-22 : 07:35:30
|
| Khal writes "I have been stuck on this for ages.I have a table egname ID Amountdave a2 70dave a2 75john b2 100john b2 50i have to insert this data in a new table and look like this:name ID Total AmountD Total AmountJdave a2 145 0john b2 0 100im using the insert statement but it wont work, I want one column to total all values for ID a2 and the other column to calculate total for ID b2" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-09-22 : 07:46:25
|
| SELECT name, ID, Sum(CASE WHEN ID='a2' THEN Amount ELSE 0 END) AS AmountD, Sum(CASE WHEN ID='b2' THEN Amount ELSE 0 END) AS AmountJFROM myTableGROUP BY name, ID |
 |
|
|
|
|
|