How to find third or nth
maximum salary from salary table(EmpID,EmpName,EmpSalary)
in Optimized way?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
Try this
For 3 you can replace any value...
Too simple if you use the sub query!
You can here just change the nth value after the LIMIT constraint.
Here in this the Sub query Select EmpSalary from Employee Order by EmpSalary DESC Limit 3; would return the top 3 salaries of the Employees. Out of the result we will choose the Minimum salary using MIN command to get the 3rd TOP salary of the employee.
To get third highest value from table
Third or nth maximum salary from salary table without using subquery
For 3rd highest salary put 2 in place of N-1
Optimized way: Instead of subquery just use limit.
See limit syntax here http://www.mysqltutorial.org/mysql-limit.aspx
Showing all 3rd highest salary:
Showing only 3rd highest salary: