CREATE TABLE EmpSalaryInfo ( Id VARCHAR(50), Name VARCHAR(50), Salary int )
insert into EmpSalaryInfo values('a1','zhou2',2000) insert into EmpSalaryInfo values('a2','zhou1',1000) insert into EmpSalaryInfo values('a3','zhou3',3000) insert into EmpSalaryInfo values('a4','zhou4',4000)
方法1 (子查询):
select top 1 name from test where salary<(select max(salary) from test) order by salary desc
方法2(定义变量)
declare @i int set @i=5 set @i=(select max(salary) from test) select top 1 name from test where salary<@i order by salary desc