mysql查询最新,mysql如何查询时间间隔大于5分钟的数据时间从现在往前推

更新时间:01-27 教程 由 心蛊 分享
mysql查询最新,mysql如何查询时间间隔大于5分钟的数据时间从现在往前推?

这个得用存储过程了,一句话查询肯定解决不了。delimiter //Create Procedure findtime()Begindeclare lastdtime datetime default null;declare thisdtime datetime default null;declare lastname varchar(10)

;declare thisname varchar(10)

;declare done tinyint default 0;declare cur cursor for select dtime,name from `table`

;declare continue handler for sqlstate '02000' set done=1;create temporary table if not exists `tmp`(dtime datetime, name varchar(10));while done1 doif lastdtime is null thenfetch cur into lastdtime,lastname;elsefetch cur into thisdtime,thisname;if timediff(thisdtime,lastdtime)>'00:05:00' theninsert into `tmp` (dtime,name)values(lastdtime,lastname)

;set lastdtime=thisdtime;set lastname=thisname;end if;end if;end while;select * from `tmp`;End//call findtime()//

声明:关于《mysql查询最新,mysql如何查询时间间隔大于5分钟的数据时间从现在往前推》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2210489.html