I have a table called Employeewith the following fields:
Employee
I want to get the two best employees with the maximum salary. How to write this request?
SQL Server 2000 +:
SELECT TOP 2 e.* FROM EMPLOYEE e ORDER BY e.salary DESC
MySQL and Postgres:
SELECT e.* FROM EMPLOYEE e ORDER BY e.salary DESC LIMIT 2
Oracle:
SELECT x.* FROM (SELECT e.*, ROWNUM as rn FROM EMPLOYEE e ORDER BY e.salary DESC) x WHERE x.rn <= 2
Try it.
SELECT * from Employee order by Salary desc limit 2 ;
2 * DESC;
- .
SELECT TOP 2 EmpID, Salary, Name FROM Employee ORDER BY Salary
:
With NumberedItems As ( Select EmpId, Salary, Name , Row_Number() Over ( Order By Salary Desc ) As SalaryRank From Employee ) Select EmpId, Salary, Name From NumberedItems Where SalaryRank <= 2
Source: https://habr.com/ru/post/1736940/More articles:OS X: вывод терминала javac искажен - javajQuery or C # ASP.Net page refresh detection - jqueryWhy in other languages there is no automatic garbage collection similar to Java Garbage Collector? - javaHow to delete columns? - unixSQL placeholder in WHERE IN, inserted rows do not work - sqlCan i interfere with iWork? - objective-cCan I access ViewState from one page to another page in Asp.Net? - asp.netCollision detection in a Java game? - javaThe best alternative to autonumber primary keys - ms-accessVectors for the 2D / 3D world in Java - javaAll Articles