数据库中的数据是30秒存一次,数据如下:
1  2010-06-01 00:00:00
2  2010-06-01 00:00:30
3  2010-06-01 00:01:00
...
...
...
n  2010-08-01 00:00:00如果我要查一个月的数据,都显示出来数据量太大,所以想把一个月的数据进行过滤,每10分钟抽取一条记录就行了,查询结果如下:
1  2010-06-01 00:00:00
2  2010-06-01 00:10:00
3  2010-06-01 00:20:00
...
...
...
n  2010-07-01 00:00:00请问各位大侠要得到上面的查询结果如何写SQL语句??????????????

解决方案 »

  1.   


    select id,time1 from(
    select id,time1,lag(time1) over(order by id) time2 from tab
    ) where (time1-time2)*24*60 = 10 and time2 is null无环境,未验证
      

  2.   

    匹配分钟即可.抽取分钟和秒钟为你想要的,例如:
    select t.*,to_char(t.birth,'mi:ss'), t.rowid from tbtime t
    where to_char(t.birth,'mi:ss') in ('00:00','10:00','20:00','30:00','40:00','50:00')
      

  3.   

    呃,恕我愚昧。。time2是null了。那么,time1-time2怎么看,结果也一样~~只显示一条么?
      

  4.   

    select t.*,to_char(t.birth,'mi:ss'), t.rowid from tbtime t
    where to_char(t.birth,'mi:ss') in ('00:00','10:00','20:00','30:00','40:00','50:00') order by t.birth需要加order by不?
      

  5.   

    select * from tb
    where substr(to_char(dt,'yyyy-mm-dd hh24:mi:ss'),15,5) in('00:00','10:00','20:00','30:00','40:00','50:00')
      

  6.   

    如果时间间隔为任意分钟(7分钟或14分钟)那么SQL语句不就越写越复杂啊?!!
      

  7.   

    select * from table
     where mod(((time-to_date('20100806123123','yyyymmdd'))*24*60),10)=0
      

  8.   

    时间差距为7或者14
    这个可以试下 借用下这位兄弟的
    select id,time1 from(
    select id,time1,lag(time1) over(order by id) time2 from tab
    ) where (time1-time2)*24*60 =7(or 14) and time2 is null
      

  9.   


    如果是按照下面这样写的话:
    select * from tb
    where substr(to_char(dt,'yyyy-mm-dd hh24:mi:ss'),15,5) in('00:00','10:00','20:00','30:00','40:00','50:00')
    那么这个substr里面取的数据都是如下的数据,
    1 44:40
    2 39:12
    3 40:03
    4 04:46
    5 18:57
    6 54:38
    7 59:50
    8 50:43
    9 30:26
    10 00:45那取出的数据不就乱套了吗?小时不一致还有日期不一致的问题不都出来了?
    所以我感觉不可取 这个方法!
      

  10.   

    晕,顺序没关系吧,自己加个order by不就可以了,关键是数据怎么筛选出来。
      

  11.   

    select id,time1 from(
    select id,time1,lag(time1) over(order by id) time2 from tab
    ) where (time1-time2)*24*60 =7(or 14) and time2 is null
    中,time1和time2的定义和“(time1-time2)*24*60 =7”看不懂!!!解释一下!!!