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 |
|
khufiamalik
Posting Yak Master
120 Posts |
Posted - 2008-10-10 : 01:05:40
|
| Hello All, I have a query which is made by the union of 3 different queries.this query returns me 3 amountsI want to Sum all these 3 amounts in same query.my query is likeSelect Amount1 from table 1select Amount2 from table 2select Amount3 from table3I juts want to sum the resultant in a Column in Same Query.Can Any one help me.Thanks in advance.I want to get the |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-10 : 01:16:34
|
| [code]select sum(case when cat=1 then val else 0 end)as amt1, sum(case when cat=2 then val else 0 end)as amt2, sum(case when cat=3 then val else 0 end)as amt3, sum(val) as totalfrom(Select Amount1 as val,1 as cat from table 1union allselect Amount2 as val,2 as cat from table 2union allselect Amount3 as val,3 as cat from table3)t[/code] |
 |
|
|
|
|
|