mysql根据时间间隔查询数据

时间:2018-05-24 10:32:33

标签: mysql sql

我有以下MySQL表:

enter image description here

我的要求是,在30分钟的时间间隔查询数据,不需要分组,这个概念,第一次遇到这样的问题,我怎样才能达到那个效果,最后一个之间的间隔接下来是30分钟

2 个答案:

答案 0 :(得分:0)

我认为这可以满足您的需求:

select t.*
from t
where t.time = (select min(t2.time)
                from t t2
                where floor(to_seconds(t2.time) / (30 * 60)) = floor(to_seconds(t.time) / (30 * 60))
               );

答案 1 :(得分:0)

前几天想到答案:

      SELECT  FROM_
      UNIXTIME(UNIX_TIMESTAMP(t.Time)- UNIX_TIMESTAMP(t.Time)%(15*60)) 
      AS timekey,DB33,Stream,`View`,Coil
      FROM (select DB33,Stream,`View`,Time,Coil from  running_check where    
     DB33=#{DB33} ORDER BY id desc  limit 10000)  as   t
      GROUP BY timekey