1、忽略表之间的关联关系
ALTER TABLE db2.dbo.table NOCHECK CONSTRAINT 关系名
2、--将没有重复的数据合并
insert into db2.dbo.table(field1,field2...) select field1,field2... from db1.dbo.table a where a.username not in (select username from db2.dbo.table)
3、将重复的数据写入临时表
select field1,field2... into 新的临时表 from db1.dbo.table a where a.username in (select username from db2.dbo.table)
1.直接把结果更新在aaa表中的语句如下
update aaa
set post = (select sum_post from (select aaa.ID,(aaa.post+bbb.post) sum_post from aaa,bbb where aaa.ID=bbb.ID) t1 where t1.ID=a.ID)
where exists (select 1 from bbb where aaa.ID =bbb.ID);
2.直接查询显示的方法参见上楼;
3.新建ccc表:
create table ccc as( select id,username,sum(post) sum_post from
(select id,username,post from aaa
union all
select id,username,post from bbb)
group by id,username; )