search

Home  >  Q&A  >  body text

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

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

大家讲道理大家讲道理2787 days ago668

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 16:04:00

    You can use stored procedures to solve this problem. If there is a timestamp field timestamp in your table and you need data every half hour in August and September, you can create a stored procedure as follows

    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;$$
    

    The basic meaning is to select half an hour of data each time. Then add half an hour to each cycle time.
    The stored procedure has not been strictly tested, but you can refer to it for ideas. . .

    reply
    0
  • 巴扎黑

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

    Why not write a sql and then execute it every half an hour to read the data in the previous half hour?

    reply
    0
  • Cancelreply