日期:2014-05-18 浏览次数:20527 次
--> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] go create table [tb]([ID] bigint,[time] datetime) insert [tb] select 12031000001,'12-03-10 14:24' union all select 12031000002,'12-03-10 14:25' union all select 12031000003,'12-03-10 14:28' --------------开始查询-------------------------- select * from tb t where exists(select 1 from tb where [time]<t.[time]) and not exists(select 1 from tb where [time]=dateadd(mi,-1,t.[time])) /* ID time -------------------- ----------------------- 12031000003 2012-03-10 14:28:00.000 (1 行受影响) */
------解决方案--------------------
create table tb (id varchar(20),time smalldatetime) insert into tb select 12031000001, '12-03-10 14:24' union all select 12031000002, '12-03-10 14:25' union all select 12031000003, '12-03-10 14:28' union all select id,time from tb a where not exists(select 1 from tb where datediff(minute,a.time,time)=-1) and not exists(select 1 from tb where datediff(minute,a.time,time)=1)
------解决方案--------------------