select * from news a
where news_id > 12345 and not exists(select 1 from news where news_id > 12345 and
news_id < a.id )
or
news_id < 12345 and not exists(select 1 from news where news_id < 12345 and
news_id > a.id )
如果不需要用一条语句写出来,那分开写的话,效率会好一些,这样写必须用一个or关键字
分开写:
select max(news_id) from news where news_id < 12345
select min(news_id) from news where news_id > 12345
news_id 是 int 吗?
是的话:
select * from news where news_id =12345+1 or news_id=12345-1
12345应该是传进来的值吧
select * from news where news_id = 变量+1 or news_id=变量-1
简单的:
select Top 1 * from ID Where news_id>12345
select Top 1 * from ID Where news_id<12345
排序规则是什么? 时间?ID?