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 |
|
zeyi
Starting Member
5 Posts |
Posted - 2009-01-12 : 13:11:21
|
| Hi, there. I have two tables, table1PGname sell_sumAA 10BB 15CC 17DD 11table2PGname sell_sumAA 10CC 11FF 5GG 12I want to have table3 or update table1 or table2, the expected table is keep PGname and add sell_sum if the PGname exist in both, and keep PGname and sell_sum if only in one table, like this:TablePGname sell_sumAA 20BB 15CC 28DD 11FF 5GG 12please offer the query how to do it? million thanks! |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-12 : 13:19:25
|
| Select PGname,Sum(sell_sum)as Sumsell from(Select Pgname,sell_sum from table1union allSelect Pgname,sell_sum from table2)tGroup by PGnameOrder by PGname |
 |
|
|
|
|
|