34,872
社区成员
发帖
与我相关
我的任务
分享
--那就:
Select Name,字段2 From Table Where ID=(Select Max(ID) From Table WHERE 字段2='b')
create table ta(vname varchar(20))
insert ta select
'111' union all select
'114' union all select
'112' union all select
'110' union all select
'113'
go
declare tb cursor scroll local
for
select * from ta
open tb
fetch first from tb -- 第1条
/*
vname
--------------------
111
(所影响的行数为 1 行)
*/
fetch ABSOLUTE 2 from tb -- 第2条
/*vname
--------------------
114
(所影响的行数为 1 行)
*/
fetch last from tb -- last
/*
vname
--------------------
113
(所影响的行数为 1 行)
*/
deallocate tb
drop table ta
Select Name From Table Where ID=(Select Max(ID) From Table)
Select Top 1 Name From Table Order By ID Desc
--你这个并不是按某个字段排序,而是取最后一条。
--可以借助临时表,如下:
select id=identity(int,1,1),* into # from [table]
select top 1 * from # order by id desc