Maison  >  Questions et réponses  >  le corps du texte

mysql - sql 在规定的时间段里读出每半个小时的数据

sql 在规定的时间段里读出每半个小时的数据 .一条语句

大家讲道理大家讲道理2742 Il y a quelques jours631

répondre à tous(2)je répondrai

  • ringa_lee

    ringa_lee2017-04-17 16:04:00

    可以使用存储过程来解决,假如你表中有一个时间戳字段timestamp,需要8,9月每半小时的数据,可以创建一个存储过程如下

    delimiter $$
    CREATE PROCEDURE test()  
    begin
        declare begintime int(10);
        set begintime =  unix_timestamp("2016-7-31 23:59:59");
        loop1:LOOP
        IF begintime > unix_timestamp("2016-9-30 23:59:59") then
             leave loop1;
         END IF;
            select * from tablename where timestamp between begintime and begintime+1800;
            set begintime = begintime + 1800;
        END LOOP loop1;
    end;$$
    

    基本意思就是每次循环select半小时数据。然后每次循环时间加半小时。
    存储过程没有严格测试,不过思路可以参考下。。。

    répondre
    0
  • 巴扎黑

    巴扎黑2017-04-17 16:04:00

    为什么不写条sql然后半小时执行一次读出前半小时内的数据呢?

    répondre
    0
  • Annulerrépondre