delete
a
from
表 a
where
id = (select top 1 id from 表 where 编号 = a.编号 and datediff(mi,时间,a.时间)<10 )
a
from
表 a
where
id = (select top 1 id from 表 where 编号 = a.编号 and datediff(mi,时间,a.时间)<10 )
解决方案 »
- SQL 2008sa登录错误,求答案...
- ******* sql server 服务器和客户端端口的问题 ***********8
- 写一个查询命令请教大家.....
- 运行存储过程时提示Error converting data type varchar to numeric.能帮看一下吗?非常感谢
- SQL2005数据库想从caché数据库里做好的视图读取数据,这个接口怎么做
- 问个菜鸟的问题
- 一个多表查询的问题~~~~大虾帮帮忙
- 用excel表更新sql表怎样方便写?条件要对应多个列,更新也要更新三个列
- 鸡毛信:这个SQL查询怎么写
- 请问在sql server中的table变量怎么用啊,最好有例子,有分送啊
- 如何实现插入过程中的数据修改?(续)——如何处理Timestamp字段?
- 这个语句如何写
ON l.编号=r.编号先说清楚问题吧
from table
group by 时间
into @tmptable declare @tmpcount int
declare @count int
set @count=1select @tmpcoutn=count(*)
from table
group by 时间while @count<=@tmpcount
begin delete from table
where 时间 <(select top 1 时间+10 as tmptime from @tmptable )
end begin
end while
可将该段代码放在存储过程中执行
数据结构:
id 编号 时间
19174 008D9D5027 2005-05-04 17:33:00
19483 008D9D5027 2005-05-04 18:15:00
19749 008D9D5027 2005-05-04 21:32:00
20002 008D9D5027 2005-05-05 07:35:00
20366 008D9D5027 2005-05-05 12:01:00
20789 008D9D5027 2005-05-05 13:17:00
20984 008D9D5027 2005-05-05 17:32:00
21327 008D9D5027 2005-05-05 18:15:00
21625 008D9D5027 2005-05-05 21:33:00
21634 FE23839293 2005-05-05 21:33:00
问题:
相同编号的记录,如何删除间隔时间小于10分钟的记录,同样时间的只留一条.
连续的间隔时间小于10分钟的记录,如
13:43:00 13:47:00 13:52:00 13:58:00 13:63:00
那么保留13:43:00 13:58:00,以此类推.
select * into #t2 from tablename where id is nullwhile exists (select * from #t1)
begin
insert #t2 select * from #t1 where 时间=(select min(时间) from #t1 where 编号=a.编号)
delete #t1
from #t1 t1,#t2 t2
where t1.编号=t2.编号
and datediff(mi,t2.时间,t1.时间)<10
enddrop table #t1delete tablename
where id not in (select id from #t2)drop table #t2
--没有测试