查询某条数据的上一条和下一条数据
RT:查询ID为“xxx”的上一条和下一条数据.
注:ID无序,ID可能为GUID.
[解决办法]
[解决办法]
;with t
as
(
select *,row_number()over(partition by ID order by getdate()) as num from tbl
)
select *from t where num=((select num from t where id='xxx')-1) and num=((select num from t where id='xxx')+1)
[解决办法]
用row_number() over (order by getdate()) 生成一个序号就ok了。
[解决办法]
order by getdate()
无异于随便取两条
没多大实际意义
[解决办法]