文章详情页
mysql - sql 在规定的时间段里读出每半个小时的数据
浏览:168日期:2022-06-16 17:10:41
问题描述
sql 在规定的时间段里读出每半个小时的数据 .一条语句


问题解答
回答1:可以使用存储过程来解决,假如你表中有一个时间戳字段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半小时数据。然后每次循环时间加半小时。存储过程没有严格测试,不过思路可以参考下。。。
回答2:为什么不写条sql然后半小时执行一次读出前半小时内的数据呢?
相关文章:
1. android glide asbitmap 在baseadpter中的问题2. angular.js - angularjs scope.$watch取不到input变化的值3. javascript - Android 的 webview 中怎么监听 url 的 hash 变化4. docker网络端口映射,没有方便点的操作方法么?5. javascript - Angular2中声明的成员变量为何显示undefined?6. php - 注册验证邮箱失效后操作问题7. mysql 欄位值移動8. mysql查询数据并不是输入数据9. mysql - thinkphp一个查询语句的实现10. 做一个抽奖系统
排行榜

网公网安备