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 |
|
calvinkwoo3000
Yak Posting Veteran
98 Posts |
Posted - 2008-10-13 : 00:21:16
|
| Hi i have a table as below year month income source___________________________2008 06 100 source12008 06 80 source22008 06 200 source12008 06 100 source2my output is year month income___________________2008 06 120 (sum(rev) source1 - sum(rev) source2) may i know what is the SQL query statement can do that???? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-13 : 00:30:04
|
| [code]SELECT year,month,SUM(CASE WHEN source='source1' THEN income ELSE 0 END)-SUM(CASE WHEN source='source2' THEN income ELSE 0 END) AS incomeFROM TableGROUP BY year,month[/code] |
 |
|
|
calvinkwoo3000
Yak Posting Veteran
98 Posts |
Posted - 2008-10-13 : 02:02:48
|
quote: Originally posted by visakh16
SELECT year,month,SUM(CASE WHEN source='source1' THEN income ELSE 0 END)-SUM(CASE WHEN source='source2' THEN income ELSE 0 END) AS incomeFROM TableGROUP BY year,month
Thank you a lot visakh16. Wish you all the best in your life. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-13 : 02:44:19
|
You're welcome thanks for the wish |
 |
|
|
calvinkwoo3000
Yak Posting Veteran
98 Posts |
Posted - 2008-10-13 : 02:48:15
|
quote: Originally posted by visakh16 You're welcome thanks for the wish
Welcome |
 |
|
|
|
|
|