-
SQL查询当前数据上一条和下一条的记录
2014-9-24 15:39:0 技术收藏 次阅读 查看评论
SQL查询当前数据上一条和下一条的记录
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 + ")";
相关日志:
- 控制面板
-
- 文章分类
-
- 最新留言
-
- 搜索
-
- 网站收藏
-
- 友情链接
-
评论列表: