我有一句话
要达到INSERT INTO table1 (count)
select  count(b.c1) count
  from table2 b
  where date(b.date) =...
  group by b.page_hash
ON DUPLICATE KEY UPDATE count=count+b.count就是说假如存在重复的情况是把原来的值加上现在查出来的值看了网上的列子重复的时候都是随便+1  没有说这种情况如INSERT INTO ipstats VALUES('192.168.0.1', 1) ON DUPLICATE KEY UPDATE clicks=clicks+1;

解决方案 »

  1.   

    INSERT INTO table1 (count)
    select  count(b.c1) count
     from table2 b
     where date(b.date) =...
     group by b.page_hash
    ON DUPLICATE KEY UPDATE count=count+values(count)另外你的count 是保留字,建议加上`count`
      

  2.   

    MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  3.   

    count+values(count)
    第一个count是table1的原值  还是 第2个是
      

  4.   

    为什么不看一下文档?连接已经贴给你了。或者自己做个试验!ON DUPLICATE KEY UPDATE count=values(count);试一下不就知道了吗?
      

  5.   

    明白了 values(count) 是刚查出来的那个 
    官方文档我一直有的 关于  insert into select ON DUPLICATE KEY UPDATE  是在介绍insert的时候讲的
    但我没找到我说的这种情况