select c_id,sum(s_sum) as su from c_own group by c_id
这条语句,读出客户ID和当前市值,现在我要把这两个值放到另外一个表中,因为当前市值是每天变化的,所以有没有办法用UPDATE语句把上面的这条语句结合到一起,因为我看到INSERT语句是可以这么做的,所以我想UPDATE也应该可以吧,请大家帮忙!!!!急!!!!!!!

解决方案 »

  1.   

    可以Update A
    Set UpdateColumn = su
    From
    UpdateTableName A
    Inner Join
    (select c_id,sum(s_sum) as su from c_own group by c_id) B
    On A.c_id = B.c_id
      

  2.   

    update tb 
    set su = t.su
    from tb,
    (select c_id,sum(s_sum) as su from c_own group by c_id) t
    where tb.c_id = t.c_id
      

  3.   

    update t1 set su=(select sum(s_sum) from c_own where c_id=t1.c_id);
      

  4.   

    哪位再把INSERT的这个格式的再给写一下啊?谢谢拉!!!
      

  5.   

    insert into tablename (字段1,字段2,...)
    子查询
    ------------------------
      

  6.   

    joe2006cn() ( ) 信誉:100    Blog  2007-03-26 15:58:44  得分: 0  
     
     
       哪位再把INSERT的这个格式的再给写一下啊?谢谢拉!!!
      
     
    ------------
    Insert InsertTableName(c_id, su)
    select c_id,sum(s_sum) as su from c_own group by c_id
      

  7.   

    如果你想要插入的表的字段也是两个(c_id,su)
    就可以这样写
    insert into tablename(c_id,su) 
    select sum(s_sum) from c_own where c_id=t1.c_id
      

  8.   

    update c_tongji set c_begin=c_info.cfund from c_tongji, (select c_id,c_fund from c_info group by c_id) c_info  where c_tongji.c_id =c_info.c_id这个查询执行的时候提示这样的错误:
    列 'c_info.c_fund' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
    请问大家怎么样更改?谢谢拉!!!
      

  9.   

    update c_tongji set c_begin=c_info.cfund from c_tongji, (select c_id,SUM(c_fund) As c_fund from c_info group by c_id) c_info  where c_tongji.c_id =c_info.c_id你沒有加SUM。
      

  10.   

    我不是要加SUM,因为我是想从INFO这个表里把c_fund的值传给c_tongji这个表的c_begin,因为这两个表的c_id是一一对应的,所以想知道怎么样写就可以把这个值传过去
      

  11.   

    那就直接這麼寫update c_tongji set c_begin=c_info.cfund from c_tongji, c_info where c_tongji.c_id =c_info.c_id