有一表a
id count
1 10
2 20
3 30
4 40;现在有表b如下:
id count
2 100
3 110怎么用把表b中id相对应的count 更新到表a中,更新后;
表a为:
id count
1 10
2 120
3 140
4 40求sql语句,多谢!
id count
1 10
2 20
3 30
4 40;现在有表b如下:
id count
2 100
3 110怎么用把表b中id相对应的count 更新到表a中,更新后;
表a为:
id count
1 10
2 120
3 140
4 40求sql语句,多谢!
create table a (id number(5),count number(10));
insert into a values (1,10);
insert into a values (2,20);
insert into a values (3,30);
insert into a values (4,40);create table b (id number(5),count number(10));
insert into b values (2,100);
insert into b values (3,110);select * from a; id count
----------------------
1 1 10
2 2 20
3 3 30
4 4 40update a set count=count+nvl((select b.count from b where a.id=b.id),0);
--提交select * from a; id count
----------------------
1 1 10
2 2 120
3 3 140
4 4 40
update a
set a.count = (select sum(count) from b where b.id = a.id)
where exists (select 1 from b where b.id = a.id);
但update a
set a.count = (select sum(count) from b where b.id = a.id)
where exists (select 1 from b where b.id = a.id);这条语句貌似无法实现LZ的要求呀??
set a.count = a.count+(select nvl(sum(count),0) from b where b.id = a.id)
where exists (select 1 from b where b.id = a.id);
merge into a
using b
on (b.id = a.id)
when matched then
update set a.count = a.count + b.count这地方没人用merge into 语法吗