数据库里面有一些数据 每一条记录 都有一个datatime的项我想从第一条开始 往后 每间隔5分钟 提取一条记录 请问怎么写SQL语句?
例如第一条是 2:10:21
那么第二条要提取的就是 2:15的内容
第三条要提取的就是 2:20的内容  因为秒数记录时间不同, 所以要忽略秒数的不同 按照'分'来作为提取的条件有几个问题
 1、必须从0:00:00开始查起,如果 0:00:00 没有数据 要从最近的一个时间段开始查起(这里是2:10:21)
2、因为某种原因,导致有的数据间隔超过了5分钟 例如第六条数据 3:19:22
遇到这种情况按照5分钟间隔来,就取不到数据了,这个时候就要找离上一条也就是第五条数据最近的一个时间来取(也就是第六条了)。
查询到的东西放在一个新表里面
请问怎么实现?2:10:21
2:11:51
2:13:51
2:15:51
2:17:21
3:19:22
3:20:52
3:22:52
3:24:22
3:26:22
3:28:22
3:29:52
3:31:53
3:33:53
3:35:23
3:36:53
3:38:53
3:40:23
4:42:23
4:43:54
......

解决方案 »

  1.   

    where dateadd(ss,date,'02:10:21')%5 = 0
      

  2.   


    要从0:00:00开始查 ...
    SS是什么?
    date又是什么?中间间隔 5分钟内没有数据 怎么处理?
      

  3.   

    where dateadd(ss,date,'00:00:00')%5 = 0
    ss 看差的秒数, date 你的日期列
      

  4.   


    报错了use  cb
    select *from T_biaoxml where dateadd(ss,2011-12-25,'00:00:00')%5 = 0服务器: 消息 403,级别 16,状态 1,行 2
    对数据类型而言运算符无效。运算符为 modulo,类型为 datetime。
      

  5.   

    create table tb(dt datetime)
    insert into tb select '2:10:21'
    insert into tb select '2:11:51'
    insert into tb select '2:13:51'
    insert into tb select '2:15:51'
    insert into tb select '2:17:21'
    insert into tb select '3:19:22'
    insert into tb select '3:20:52'
    insert into tb select '3:22:52'
    insert into tb select '3:24:22'
    insert into tb select '3:26:22'
    insert into tb select '3:28:22'
    insert into tb select '3:29:52'
    insert into tb select '3:31:53'
    insert into tb select '3:33:53'
    insert into tb select '3:35:23'
    insert into tb select '3:36:53'
    insert into tb select '3:38:53'
    insert into tb select '3:40:23'
    insert into tb select '4:42:23'
    insert into tb select '4:43:54'
    go
    select top 100 id=identity(int,1,1) into # from sysobjects
    select convert(varchar(8),a.dt,108)dt from tb a inner join(
    select dateadd(mi,(b.id-1)*5,convert(varchar(3),min(a.dt),108)+ltrim(datepart(mi,min(a.dt))/5*5))dt from tb a,# b
    group by b.id
    )b on a.dt>=b.dt and a.dt<dateadd(mi,5,b.dt) and not exists(select 1 from tb where dt>b.dt and dt<a.dt)
    /*
    dt
    --------
    02:10:21
    02:15:51
    03:19:22
    03:20:52
    03:26:22
    03:31:53
    03:35:23
    03:40:23
    04:42:23(9 行受影响)*/
    go
    drop table tb,#
      

  6.   


    create table tb(date datetime)
    insert into tb select '2:10:21'
    insert into tb select '2:11:51'
    insert into tb select '2:13:51'
    insert into tb select '2:15:51'
    insert into tb select '2:17:21'
    insert into tb select '3:19:22'
    insert into tb select '3:20:52'
    insert into tb select '3:22:52'
    insert into tb select '3:24:22'
    insert into tb select '3:26:22'
    insert into tb select '3:28:22'
    insert into tb select '3:29:52'
    insert into tb select '3:31:53'
    insert into tb select '3:33:53'
    insert into tb select '3:35:23'
    insert into tb select '3:36:53'
    insert into tb select '3:38:53'
    insert into tb select '3:40:23'
    insert into tb select '4:42:23'
    insert into tb select '4:43:54'
    goselect *
    from tb
    where datediff(ss,date,'02:10:21')%5 = 0drop table tb/**********************date
    -----------------------
    1900-01-01 02:10:21.000
    1900-01-01 02:11:51.000
    1900-01-01 02:13:51.000
    1900-01-01 02:15:51.000
    1900-01-01 02:17:21.000(5 行受影响)
      

  7.   


    (所影响的行数为 68980 行)服务器: 消息 2714,级别 16,状态 6,行 2
    数据库中已存在名为 '#' 的对象。
    请问 select top 100 id=identity(int,1,1) into # from sysobjects
    是什么意思?
      

  8.   


    我不理解的是
     
    select top 100 id=identity(int,1,1) into # from sysobjects这一句是啥意思哟?
      

  9.   

    select top 100 id=identity(int,1,1) into # from sysobjects# 是什么意思? 为什么在sysobjects里面?
      

  10.   

    select top 100 id=identity(int,1,1) into # from sysobjects# 是什么意思? 为什么在sysobjects里面?