table1 id,summoney   table2 id, money,kind
   table1为空表,
    table2   1,10,a
             2,21,b
             3,15,c
      
             1,20,b
             2,20,a      
   现在怎样将table2里面kind为a和b的money相加的和存入到table1的summoney里面
     table1和table2里面的id对应,在table1里面id不重复,并且table1里面只存储kind为a和b或a,b的和的字段
   

解决方案 »

  1.   

    insert into table1 (id,summoney) select id ,sum(money) from table2 group by id
      

  2.   

    insert into table1(id,summoney)
    select id,sum(money)
    from table2
    group by id
      

  3.   

    怎么个相加办法 看的不是很懂啊
    猜一个
    insert into table1 
    select id,sum(money) from table2  where kind in('a','b')
    group by id 
      

  4.   

    insert into table1 (id,summoney) select id ,sum(money) from table2 group by id
      

  5.   

    如果你的table1有数据,那要用update,如果没数据,就用insert
    我给个insert 的例子insert into table1
    select a.id,b.money+b.kind
    from table1 a inner join table2 b on a.id=b.id
      

  6.   

     b.money+b.kind  什么意思?
       我要的是,kind为a和kind为b 的money的和 放入table1的summoney中
      

  7.   


    select id,sum(money) from table2  where kind in('a','b')
    group by id 这个有问题没?