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()
无异于随便取两条
没多大实际意义
------解决方案--------------------