How to get second-highest salary employees in a table

后端 未结 30 1024
离开以前
离开以前 2020-12-23 20:15

It\'s a question I got this afternoon:

There a table contains ID, Name, and Salary of Employees, get names of the second-highest salary employees, in SQL Server

30条回答
  •  心在旅途
    2020-12-23 20:54

    declare
    
    cntr number :=0;
    
    cursor c1 is
    
    select salary from employees order by salary desc;
    
    z c1%rowtype;
    
    begin
    
    open c1;
    
    fetch c1 into z;
    
    while (c1%found) and (cntr <= 1) loop
    
    
    cntr := cntr + 1;
    
    fetch c1 into z;
    
    dbms_output.put_line(z.salary);
    
    end loop;
    
    end;
    

提交回复
热议问题