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)
mysql中,我想从数据库里提取出0:00到20:00之间每隔十五分钟的记录?
1select * from t_rainfall where time>='开始时间' and time<='结束时间' and date_format(time,'%i')%15=0 and date_format(time,'%s')=0
date_format(time,'%i')获取分钟数,%15就是对分钟取余,等于0就是15的倍数
date_format(time,'%s')获取秒数
这种方法简单,对于小表可以,如果表的数据量太大要换种方式

