id是指当前数据news_id参数
方法一:
string preSql = "select top 1 * from news where news_id < " + id + " order by news_id DESC"
string nextSql = "select top 1 * from news where news_id > " + id + " order by news_id ASC"
方法二:
string preSql = "select * from [news] where news_id = (select MAX(news_id) from [news] where news_id<"+ id + ")";
string nextSql = "select * from [news] where news_id = (select MIN(news_id) from [news] where news_id>"+ id + ")";
转载之(http://ruyu108.blog.163.com/blog/static/101231082010101992117165/)
SQL查询技巧:获取新闻数据的前后条目
本文介绍了两种方法来使用SQL查询获取指定新闻ID前后最近的新闻条目,通过设置条件来筛选数据并按ID进行排序。

被折叠的 条评论
为什么被折叠?



