SQL中如何合并两个表,对应字段值如何自动相加??

如图有表一和表二,如何得出表3,表1中有字段c,表2中没有,得出的表3不能丢了字段c,如何写select查询语?

第1个回答  推荐于2018-05-06
select ip,addr,sum(次数) from(
select ip,addr,次数 from table1
union all
select ip,addr,次数 from table2)
group by ip,addr本回答被提问者和网友采纳
第2个回答  2012-10-09
select a.ip,a.addr,isnull(a.次数,0)+isnull(b.次数,0) 次数 from 表1 a left join 表2 b on a.ip=b.ip and a.addr=b.addr
相似回答