SQL查询当前数据上一条和下一条的记录

SQL查询当前数据上一条和下一条的记录

    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 + ")";
2014-9-24 15:39:0 工作杂记 次阅读 0条评论
控制面板
您好,欢迎到访网站!
  [查看权限]
文章分类
相册列表
搜索
最新留言
网站收藏
友情链接