比如有两个表  表A,表B
       表A 中有两个字段
       point_id 和 容量
       表B中有也两个字段
        point_id 和 总容量
表A中point_id 唯一
表B中point_id 不唯一我想把表B中point_id相同的 容量字段的数值累加起来 
将得到的值传递给表A中与表B具有相同point_id的 容量字段。
高手指点啊!

解决方案 »

  1.   

    一条语句就可实现,自己转化成存储过程吧update tableA SET 总容量=(select sum(容量) from tableB where point_id = '7067') where point_id  = '7067'
      

  2.   

    update b set b.总容量=b.总容量+a.容量 from a,b where a.point_id=b.point_id
      

  3.   

    declare @i as int
    --//建临时表
    create table temptable([id] [int] IDENTITY (1, 1) NOT NULL ,point_id int,容量 int)
    --//把结果存入临时表
    insert into temptable(point_id,容量)
    select point_id,sum(容量) from B group by point_id
    --//得到临时表行数
    select @i=count(*) from temptable
    --//顺序更新A表
    while @i>0
    begin
    update A set A.容量=temptable.容量 where A.poit_id=temptable.point_id and temptable.id=@i
    set @i=@i-1
    end
    --//删除临时表
    drop table temptable
      

  4.   

    CREATE OR REPLACE VIEW VIEW_TEST AS
    SELECT SUM(总容量) as num,point_id FROM B GROUP BY point_id;
    SELECT A.point_id,A.容量,VIEW_TEST.sum from A,VIEW_TEST where A.point_id=VIEW_TEST.point_id(+);