根据id和条件查出该信息相邻的上一条、下一条
刚才有前辈说没有数据表,所以再开一篇,^_^,等一下一起结掉
http://bbs.csdn.net/topics/390617192
根据currentId和条件查询该信息的上一条或下一条数据信息
数据表信息:
article:id,classid,title,content,userid,addtime,edittime
条件:userid=77 and classid=5
排序条件:edittime desc
[解决办法]
说好的数据呢?
[解决办法]
;With T as (
select row_number() over (order by edittime desc ) as Row ,* from article
)
,T2 AS (
SELECT * FROM t WHERE userid=77 and classid=5
)
--上一条
select * from T where Row = (select Row from T2) -1
UNION ALL
--下一条
select * from T where Row = (select Row from T2) +1
declare @id int
set @id=xxx
select top 1 * from tb where ID>@id order by Id asc
union all
select top 1 * from tb where ID<@id order by Id desc
declare @id int
set @id=xx
SELECT * FROM (select top 1 * from tb where id>@id order by id ASC) t1
UNION ALL
SELECT * FROM (select top 1 * from tb where id<@id order by id DESC) t2
select * from article a WHERE EXISTS
(SELECT 1 FROM
(SELECT id FROM article where userid=77 and classid=5) b
WHERE a.id BETWEEN b.id-1 AND b.id+1) order by edittime desc