本帖最后由 oAnJing1234 于 2012-11-12 17:23:45 编辑

解决方案 »

  1.   

    INSERT INTO B(a_id,new_count)
    SELECT id,count/2 FROM A
      

  2.   

    insert into b (a_id,new_count) select id,`count`/2 from a;
      

  3.   

    谢谢上边两位 已经解决问题了  现在情况复杂了(就复杂这一次)
    b表中还有其他字段
    id a_id new_count other
    1 1 24 10
    2 2 25 10
    3 3 48 10
    4 4 25 10
    5 5 33 10
    6 10 50 101.让b表中的other字段都为10 但是other默认的不是10
    2.b表中已经存在对应a表的记录就不增加了
      
      

  4.   

    假设a_id是唯一 的
    insert into b(a_id,new_count,other)
    SELECT a.id,a.count/2,10 FROM A ON DUPLICATE KEY UPDATE other=10
      

  5.   

    insert into b (a_id,new_count,other) 
    select id,`count`/2,10 from a 
    where id not in (select a_id from b);
      

  6.   

    insert into b(a_id,new_count,other)
    select id,'count'/2,10 from a
    where id not in(select a_id from b);
      

  7.   

    这次提问学到了很多 ON DUPLICATE KEY UPDATE意外知道 自己做的系统一直在优化 现在数据库32M了 感觉sql还有很多的可以优化  自己只知道些简单的mysql 还是要不断的学习 谢谢上边回答问题的大牛们