主题:【求助】SQL怎样用一个表中的信息来更新另外一个表 -- 铁手

大河奔流 导读 复 10 阅 18445

全看 分页 树展 一览 主题

2016-04-20 15:32:38
4190906 复 4189313
四四方方四四方方`6664`/bbsIMG/face/0012.gif`70`5202`165`22472`正五品上:中散大夫|定远将军`2005-05-10 20:21:20`
试试 1

create table t1 (

id number(2),

point number(4)

)

;

create table t2 (

id number(2),

total number(4)

)

;

insert into t1 values (12, 1);

insert into t1 values (12, 2);

insert into t1 values (12, 3);

insert into t1 values (12, 4);

insert into t1 values (13, 11);

insert into t1 values (13, 12);

insert into t1 values (13, 13);

insert into t1 values (13, 14);

select * from t1;

=========

id point

=========

12 1

12 2

12 3

12 4

13 11

13 12

13 13

13 14

insert into t2 values (12, 0);

insert into t2 values (13, 0);

select * from t2;

=========

id total

=========

12 0

13 0

update t2 a set total = (select sum(point) from t1 b where b.id = a.id group by a.id);

select * from t2;

=========

id total

=========

12 10

13 50

drop table t1 purge;

drop table t2 purge;


2016-04-20 15:32:38

全看 分页 树展 一览 主题