我有两张表
表一:
个人帐号   销售总额
01          0
02          0
03          0表二:
个人帐号     销售费用  
01           100
02            70
01            90
03           200
03            30
01            20
02            50
现在写这SQL,用表二的按个人帐号汇总数 按个人帐号更到销售总额,哪位高手帮帮我!

解决方案 »

  1.   

    update table1 
      set 销售总额 = (select sum(销售费用) from table2 group by 个人帐号 where table2.个人帐号 = table1.个人帐号)
      

  2.   

    update tb1 set 销售总额=b.销售总额 
      

  3.   

    update   tb1   set   销售总额=b.销售总额   
    FROM tb1 a 
    inner join 
    (select 个人帐号,sum(销售费用) 销售费用 group by 个人帐号 from tb2)as b
    on a.个人帐号=b.个人帐号
      

  4.   

    merge into t1 a
    using (select 帐号,sum(费用)all_fee from t2 group by 帐号) b
    on(a.帐号=b.帐号)
    when matched then
    update set a.fee=a.费用+b.all_fee;如果不是10g,还要加个when not matched子句。
      

  5.   


    update t1
    set 销售总额 =(select sum(销售费用 ) as money from t2 where 个人帐号=t1.个人帐号)
      

  6.   

    同意这个
    update   t1 
    set   销售总额   =(select   sum(销售费用   )   as   money   from   t2   where   个人帐号=t1.个人帐号) 
    但是这样会把本来第一个表中的销售费用忽略不计
      

  7.   

    如果像每次把第一个表的数据也累加
    如下
    update testa
    set testa.b=(select 
                  sum(b) 
                 from 
                  (select * from testb union all select * from testa) 
                 where testa.a=a
                )testa表一
    testb表二列a 个人账号
    列b 销售总额