查询结果数不确定,怎么只列出最后30条,不能倒排序。
如题
[解决办法]
如何从表中用SELECT语句提取最后10条数据呢?
declare @num as int
select @num = count(*) from authors
set @num = @num - 10
declare @sql as varchar(200)
set @sql = 'select * from authors where au_id not in (select top ' + cast(@num as char) + ' au_id from authors) '
exec (@sql)
[解决办法]
前提要有的,否则无法实现
1,在有主键,
2.有一个惟一键的排序
以上两个条件满足,就可以用楼上的办法了.