| Author |
Topic |
|
laailalalaa
Yak Posting Veteran
57 Posts |
Posted - 2010-04-12 : 02:10:32
|
| i have table1(accountno, operationtype, amountofmoney,date),where operationtype = A or B. i need to write a select stmnt that displays:account, sum of amountofmoney for operations of type A, sum of amountofmoney for operations of type B for the account.any ideas on how to proceed?thank u |
|
|
mrm23
Posting Yak Master
198 Posts |
Posted - 2010-04-12 : 02:25:42
|
| you can try this: SELECT SUM(CASE WHEN Column2 = 'Some Value' THEN Column1 ELSE 0 END) as FieldNeeded1,here in your example you can take :SELECT accountno ,SUM(CASE WHEN operationtype = 'A' THEN amountofmoney ELSE 0 END) as amtA ,SUM(CASE WHEN operationtype = 'B' THEN amountofmoney ELSE 0 END) as amtBFROM .....Hope this helps.... |
 |
|
|
laailalalaa
Yak Posting Veteran
57 Posts |
Posted - 2010-04-12 : 03:21:39
|
thanks, that worked.. and was awesome :Dquote: Originally posted by mrm23 you can try this: SELECT SUM(CASE WHEN Column2 = 'Some Value' THEN Column1 ELSE 0 END) as FieldNeeded1,here in your example you can take :SELECT accountno ,SUM(CASE WHEN operationtype = 'A' THEN amountofmoney ELSE 0 END) as amtA ,SUM(CASE WHEN operationtype = 'B' THEN amountofmoney ELSE 0 END) as amtBFROM .....Hope this helps....
|
 |
|
|
mrm23
Posting Yak Master
198 Posts |
Posted - 2010-04-13 : 01:24:44
|
| you are welcome :) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
laailalalaa
Yak Posting Veteran
57 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
laailalalaa
Yak Posting Veteran
57 Posts |
|
|
|