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 |
|
cy163
Starting Member
2 Posts |
Posted - 2008-10-09 : 01:45:04
|
I have two tables tb1 and tb2. I would like to sum up field values from two tables. How to do this using a SQL statement.tb1Name SalaryBob 1000Tom 2000John 3000Winson 4000tb2Name BonusBob 100Tom 200I would like to get the following resultName TotalBob 1100Tom 2200John 3000Winson 4000I have tried with the following statement but no luck.SELEC tb1.Name, SUM(tb1.Salary + tb2.Bonus) Total From tb1, tb2 WHERE tb1.Name = tb2.Name group by tb1.Name order by Total |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-09 : 01:51:02
|
| [code]SELECT t.Name,SUM(t.Salary)FROM(SELECT Name,SalaryFROM tb1UNION ALLSELECT Name,BonusFROM tb2)tGROUP BY t.Name[/code] |
 |
|
|
|
|
|