34,590
社区成员
发帖
与我相关
我的任务
分享
select distinct name from tableName where datediff(hour,getdate(),[time])>1
create table tb(name varchar(10),time datetime)
insert tb select 'a', '2008-03-01 02:00'
union all select 'a', '2008-03-01 03:00'
union all select 'a', '2008-03-01 02:30'
union all select 'b', '2008-03-01 02:30'
union all select 'b', '2008-03-01 01:00'
union all select 'c', '2008-03-01 02:00'
union all select 'c', '2008-03-01 02:30'
go
select distinct name from tb a where
exists(select 1 from tb where a.name = name and datediff(hh,time,a.time)>=1)
go
drop table tb
/*
name
----------
a
b
*/