日期:2014-05-17 浏览次数:20594 次
;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
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
select top 1 * from 表 where Id<@currentId order by id desc--上一條
uinon all
select top 1 * from 表 where Id>@currentId order by id asc--下一條