如何查找表最后10位记录,注意最后10位的id不知道?

来源:百度知道 编辑:UC知道 时间:2024/06/28 10:58:58
如何查找表最后10位记录,注意最后10位的id不知道?

declare @i int
select @i=count(*)-10 from 表名
select @i=case when @i<0 then 0 else @i end)

select * from table where ID not in(select top (@i) ID from table)
没有大小关系

如果为SQL2005可用CTE或row_number实现