select * from 表 a where a.id=(select id from 表 b where id=a.id and abs(datediff(s,a.stamp,b.stamp))<=5)

解决方案 »

  1.   

    select obj_id,count(*) from
    (SELECT a.obj_id,a.stamp astamp,b.stamp bstamp
    from t_temp a left join t_temp b on a.obj_id=b.obj_id 
    and b.stamp=(select min(stamp) from t_temp where obj_id=a.obj_id and stamp>a.stamp)
    where datediff(s,a.stamp,b.stamp)<=5) m
    group by obj_id having count(*)>=3
      

  2.   

    select obj_id,count(*) from
    (SELECT a.obj_id,a.stamp astamp,
    (select min(stamp) from t_temp b where b.obj_id=a.obj_id and b.stamp>a.stamp and datediff(s,a.stamp,b.stamp)<=5) bstamp
    from t_temp a ) m where bstamp IS not NULL
    group by obj_id having count(*)>=3这样也可以
      

  3.   

    出现了三次以上的间隔不超过5秒的OBJ_ID
    ----------------------------------------要求连续3次吗?
      

  4.   

    出现了三次以上的间隔不超过5秒的OBJ_ID
    ----------------------------------------
    要求连续3次吗?
    ----------------------------------------
    要求连续的,因为不连续的,有很多的偶然性.
      

  5.   

    select obj_id from
    (
    select *,stamp2 = (select max(stamp) from t_temp where obj_id = a.obj_id and id < a.id)
    from t_temp a
    )tt 
    where datediff(ss,stamp2,stamp) <= 5 
    group by obj_id
    having count(1) > 3--结果
    1000
    4000
      

  6.   

    select obj_id from
        (select obj_id,astamp,bstamp,(select min(stamp) from t_temp n where n.obj_id=m.obj_id and n.stamp>m.bstamp and datediff(s,m.bstamp,n.stamp)<=5) cstamp
            from
            (
                SELECT a.obj_id,a.stamp astamp,(select min(stamp) from t_temp b where b.obj_id=a.obj_id and b.stamp>a.stamp and datediff(s,a.stamp,b.stamp)<=5) bstamp
                    from t_temp a 
            ) m 
            where bstamp IS not NULL 
        ) t where cstamp IS not NULL 
    group by obj_id having count(*)>=3一样的道理,连续3次也可以这样写
      

  7.   

    简单一点:select distinct obj_id from
    (
    select *,stamp1=(select top 1 stamp from t_temp b where a.obj_id=b.obj_id and datediff(s,a.stamp,b.stamp)<5 order by stamp desc) from t_temp a
    )a
    group by obj_id,stamp1
    having count(*)>=3
    order by 1
      

  8.   

    select obj_id from
        (select obj_id,astamp,bstamp,(select min(stamp) from t_temp n where n.obj_id=m.obj_id and n.stamp>m.bstamp and datediff(s,m.bstamp,n.stamp)<=5) cstamp
            from
            (
                SELECT a.obj_id,a.stamp astamp,(select min(stamp) from t_temp b where b.obj_id=a.obj_id and b.stamp>a.stamp and datediff(s,a.stamp,b.stamp)<=5) bstamp
                    from t_temp a 
            ) m 
            where bstamp IS not NULL 
        ) t where cstamp IS not NULL 
    group by obj_id having count(*)>=3
    这么些应该对阿
      

  9.   

    更正一下我的,有点Bug,来个更简单的:select * from t_temp a
    where (select count(*) from t_temp b where a.obj_id=b.obj_id and a.stamp<=b.stamp and datediff(ss,a.stamp,b.stamp)<=5)>=3
    order by 2
      

  10.   

    select b.obj_id,count(*)
    from t_temp b 
    where  datediff(ss,(select a.stamp from t_temp a where a.obj_id=b.obj_id and b.id=a.id+1),b.stamp)<=5 
    group by b.obj_id
    having count(*)>=4
      

  11.   


    出现了三次以上的间隔不超过5秒的OBJ_ID
    ----------------------------------------
    要求连续3次吗?
    ----------------------------------------
    要求连续的,因为不连续的,有很多的偶然性.
    ----------------------------------------大家注意一下这个~