很奇怪,我在事件中使用select count(*) from 表名  的操作报错.... 一时没有了思路.如何通过事件定时对 一个表中的 几个列值进行保存 (表自增长id,按当前时间,列名1,列名2) 保存在一个old data表中呢?请帮帮我吧~~~~~

解决方案 »

  1.   

    insert into  old  seelct * from tb
      

  2.   

    1064 you have an error in your sql syntax;check the manual that corresponds to your mysql server version for the right syntax to use near 'while @cnt >0 do
    set @cnt= cnt -1;
    end while' at line 1
    代码是这样的
    set @cnt_i= (select count(*) from bupin_fh );
    while @cnt >0 do
    set @cnt = @cnt - 1;
    end while;想在set @cnt =@cnt -1; 前按照行数 查询并写入记录的,但是写到这里就错了.好象不是 d  cuowu  .....
    不明白啊 求解
      

  3.   

    好象不是count(*)的错误 ~~~ while  就不行
      

  4.   

    你的完整CREATE EVENT 语句是什么?有没有加 delimiter // ?
      

  5.   

    delimiter |CREATE EVENT e_daily
        ON SCHEDULE
          EVERY 1 DAY
        COMMENT 'Saves total number of sessions then clears the table each day'
        DO
          BEGIN
            INSERT INTO site_activity.totals (time, total)
              SELECT CURRENT_TIMESTAMP, COUNT(*)
                FROM site_activity.sessions;
            DELETE FROM site_activity.sessions;
          END |delimiter ;
      

  6.   


    + set @cnt= cnt -1;
      这晨 cnt 没有 @ 号呀,你后面的是改的了?
    + set @cnt_i= (select count(*) from bupin_fh );
      是不是改成:set @cnt_i := (select count(*) from bupin_fh );
    + set @cnt = @cnt - 1;
      是不是改成:set @cnt := @cnt - 1;
    + 另外你上面给的代码是完整的吗?如果不是,while 语句应该在过程/函数中使用吧
      

  7.   

    改成下面那样还是不行啊.
     set @cnt := (select count(*) from bupin_fh );
    while @cnt >0 do
    set @cnt := @cnt - 1;
    end while;我用的是navicat 8 for mysql中 使用工具 来创建的事件~~~~~~
    出来我看到的就是
    BEGIN 和 END 之间的了.其他的都是自动的.再加入while之前 是能够保存和运行的.
      

  8.   

    CREATE DEFINER=`root`@`%` EVENT `auto_save` ON SCHEDULE EVERY 1 DAY STARTS '2011-11-29 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO set @cnt = (select count(*) from bupin_fh );
    好象是这个吧
      

  9.   

    如果用查询语句  这样写
    CREATE EVENT aout_save
      ON SCHEDULE
      EVERY 1 DAY
      DO
      BEGIN
      set @cnt = (select count(*) from bupin_fh );
      END |delimiter ;还是报错[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6
      

  10.   

    DELIMITER $$
    CREATE EVENT aout_save
       ON SCHEDULE
       EVERY 1 DAY
       DO
       BEGIN
       SET @cnt = (SELECT COUNT(*) FROM bupin_fh );
       END $$DELIMITER ;