日期:2014-05-18  浏览次数:20464 次

sql 数据挖掘问题
我想把数据表中的   删除   id   相同的   日期相隔在3分钟的记录.也就是说只保留   id
相同   日期在3分钟以内的一条记录,怎么写sql语句.

------解决方案--------------------

create table ttt(id int identity,name varchar(10),createtime datetime)


delete a from ttt a
where exists(select 1 from ttt where a.name=name and datediff(mi,a.createtime,createtime) <=3 and a.createtime <createtime)