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 |
|
Stan1978
Starting Member
31 Posts |
Posted - 2011-07-13 : 04:42:07
|
| Thank you for taking the time to read this question.I have one table in a poor (my opinion) data structure. Accid ----- Trans ------ Cash ---- Bonus1 -------- Deposit ----- 10 ---- 01 -------- Deposit ----- 50---- 01 -------- Sale ------- -5 ---- 01 -------- Sale -------- 0 ---- -81 -------- Withdrawal - -25 ---- 02 -------- Sale -------- -10 ---- 02 -------- Sale ------- -10---- 0I need to aggregate on account id, and sum the amounts for each specific Trans type?Accid - Sale Cash - Sale Bonus - Deposit - Withdrawal1, -5, -8, 60, -252, -20, 0, 0 , 0 Thanks in advance |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-07-13 : 04:51:46
|
This?selectAccid,sum(case when Trans='Cash' then Cash else 0 end) as [Sale Cash],sum(case when Trans='Bonus' then Bonus else 0 end) as [Sale Bonus],sum(case when Trans='Deposit' then Cash else 0 end) as [Deposit],sum(case when Trans='Withdrawal' then Cash else 0 end) as [Withdrawal]from tablegroup by Accid No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Stan1978
Starting Member
31 Posts |
Posted - 2011-07-13 : 04:55:20
|
| Legend thank you. |
 |
|
|
|
|
|
|
|