当前位置: 代码迷 >> Sql Server >> 查询表里的最后一条数据?解决办法
  详细解决方案

查询表里的最后一条数据?解决办法

热度:50   发布时间:2016-04-27 17:51:02.0
查询表里的最后一条数据?
查询表里的最后一条数据?     没有ID     没有时间     How   to   do   ?

------解决方案--------------------
declare @num as int
select @num = count(*) from authors
set @num = @num - 1

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)

------解决方案--------------------
2005实现:
select top 1 *
from (select *,row=row_number() over( order by id) from sysobjects)ta
order by row desc
  相关解决方案