当前位置: 代码迷 >> Oracle管理 >> 二个表,update求汇总
  详细解决方案

二个表,update求汇总

热度:32   发布时间:2016-04-24 05:04:12.0
2个表,update求汇总
比我有2个表 a,b

a是这样的

kpbh totalsum
0001
0002
0003
0004

b是这样的

kpbh totalsum
0001 1
0001 2
0002 3
0002 4
0003 5
0003 6
0004 7
0004 8
0005 9

现在我想更新表a 的totalsum 等于 b相同kpbh 的求和
我的语句应该怎么写?

------解决方案--------------------
探讨
SQL code


--1
update a
set totalsum =(select sum(totalsum ) from b where b.kpbh = a.kpbh)
where exists(select 1 from a,b where a.kpbh=b.kpbh);

--2
merge into a
using (select kpbh,……
  相关解决方案