mysql - sql 在规定的时间段里读出每半个小时的数据
大家讲道理
大家讲道理 2017-04-17 16:02:00
0
2
671

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

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
左手右手慢动作

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. . .

巴扎黑

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template