if not object_id('tb') is null drop table tb Go Create table tb([Id] int,[stu_name] nvarchar(2),[stu_sex] nvarchar(1)) Insert tb select 1,N'王强',N'男' union all select 3,N'李娜',N'女' union all select 4,N'张峰',N'男' union all select 6,N'钟柳',N'女' Go ---如果ID递增 select top 1 ID from tb where id<(select top 1 ID from tb where stu_name=N'李娜') order by id desc /* ID ----------- 1(1 個資料列受到影響) */
drop table tb
Go
Create table tb([Id] int,[stu_name] nvarchar(2),[stu_sex] nvarchar(1))
Insert tb
select 1,N'王强',N'男' union all
select 3,N'李娜',N'女' union all
select 4,N'张峰',N'男' union all
select 6,N'钟柳',N'女'
Go
---如果ID递增
select top 1 ID
from tb
where id<(select top 1 ID
from tb
where stu_name=N'李娜')
order by id desc
/*
ID
-----------
1(1 個資料列受到影響)
*/
up
< 可以解决这个问题。