日期:2014-05-17 浏览次数:20643 次
;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