--> 测试数据:[test] if object_id('[test]') is not null drop table [test] create table [test]([ID] int,[值] int) insert [test] select 1,1 union all select 2,4 union all select 3,5 union all select 4,6 union all select 5,7 union all select 6,8select top 1 * from( select top 3 * from test order by GETDATE())t order by [值] desc /* ID 值 3 5 */
select max([值]) from ( select top 3 * from yourtable order by id asc ) a
--> 测试数据:[test]
if object_id('[test]') is not null
drop table [test]
create table [test]([ID] int,[值] int)
insert [test]
select 1,1 union all
select 2,4 union all
select 3,5 union all
select 4,6 union all
select 5,7 union all
select 6,8select top 1 * from(
select top 3 * from test order by GETDATE())t
order by [值] desc
/*
ID 值
3 5
*/
select top 3 * from yourtable order by id asc
) a