Find max and second max salary for a employee table MySQL

前端 未结 30 1908
忘掉有多难
忘掉有多难 2020-12-12 21:19

Suppose that you are given the following simple database table called Employee that has 2 columns named Employee ID and Salary:

  Employee
  Employee ID    S         


        
30条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 21:33

    select * from emp where sal =(select max(sal) from emp where eno in(select eno from emp where sal <(select max(sal)from emp )));
    

    try the above code ....

    if you want the third max record then add another nested query "select max(sal)from emp" inside the bracket of the last query and give less than operator in front of it.

提交回复
热议问题