为什么用游标? update b set count=isnull(count,0)+ sumcount from b,(select A.id,count(A.id) as sumcount from a WHERE A.ID=B.ID group by A.id ) c where c.id=b.id ---如果A中存在,B中不存在,向B中插入 insert into b(id,name,count) select a.id,a.name,conut(a.id) from a left b on a.id=b.id where b.id is null group by a.id,a.name
update b set count=isnull(count,0)+ sumcount
from b,(select A.id,count(A.id) as sumcount from a WHERE A.ID=B.ID group by A.id ) c
where c.id=b.id
---如果A中存在,B中不存在,向B中插入
insert into b(id,name,count)
select a.id,a.name,conut(a.id)
from a left b on a.id=b.id
where b.id is null
group by a.id,a.name