日期:2014-05-16  浏览次数:20870 次

求与当前时间一前一后的记录的sql
ID TIME  
1 6:00
2 7:00
3 8:00

如果现在是7:30,则返回第2,3条记录
请不使用union all语句哦,非常感谢!

------解决方案--------------------
select *
from tb
where substring(time,':',1)>='7:30'
order by id
limit 2;
------解决方案--------------------
详细说明
SELECT * FROM `qbb` 
WHERE TIMEDIFF(st,'7:30')>0 OR HOUR(TIME(st))=HOUR(TIME('7:30'))

or

SELECT * FROM `qbb` 
WHERE HOUR(TIME(st))>=HOUR(TIME('7:30'))
------解决方案--------------------
SQL code
select *
from table1 a
where (`TIME`<now() and not exists (select 1 from table1 where `TIME`<now() and `TIME`>a.`TIME`))
or (`TIME`>now() and not exists (select 1 from table1 where `TIME`>now() and `TIME`<a.`TIME`))