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

sql查询问题 在线等
ID time
12031000001 12-03-10 14:24
12031000002 12-03-10 14:25
12031000003 12-03-10 14:28

有如上这样的表。。。
数据每分钟更新一条。。。

后面是时间
现在数据 出错。。。

如何查出那个时间 数据出错了???

 

------解决方案--------------------
SQL code
--> 测试数据:[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 行受影响)

*/

------解决方案--------------------
SQL code
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)

------解决方案--------------------
探讨
ID time
12031000001 12-03-10 14:24
12031000002 12-03-10 14:25
12031000003 12-03-10 14:28

有如上这样的表。。。
数据每分钟更新一条。。。

后面是时间
现在数据 出错。。。

如何查出那个时间 数据出错了???