Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Como encontrar o segundo maior salário no mysql


Tente isto:
SELECT emp_name,salary 
FROM Employee
WHERE salary = (SELECT DISTINCT salary FROM Employee as emp1
                WHERE (SELECT COUNT(DISTINCT salary)=2 FROM Employee as emp2
                WHERE emp1.salary <= emp2.salary)) 
ORDER BY emp_name