create table tb(id int,[time] time) insert into tb select 1,'6:00' insert into tb select 2,'7:00' insert into tb select 3,'8:00' insert into tb select 4,'9:00' go declare @s time set @s='7:30' select * from tb a where time>@s and not exists(select 1 from tb where time<a.time and time>@s) or time<@s and not exists(select 1 from tb where time>a.time and time<@s) /* id time ----------- ---------------- 2 07:00:00.0000000 3 08:00:00.0000000(2 行受影响) */ go drop table tb
--如果是sql server则如下:select top 1 * from tb where time < '7:30' order by time desc select top 1 * from tb where time > '7:30' order by time
insert into tb select 1,'6:00'
insert into tb select 2,'7:00'
insert into tb select 3,'8:00'
insert into tb select 4,'9:00'
go
declare @s time
set @s='7:30'
select * from tb a
where time>@s and not exists(select 1 from tb where time<a.time and time>@s)
or time<@s and not exists(select 1 from tb where time>a.time and time<@s)
/*
id time
----------- ----------------
2 07:00:00.0000000
3 08:00:00.0000000(2 行受影响)
*/
go
drop table tb
select top 1 * from tb where time > '7:30' order by time