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 Query
Put n= which value you want
If you want optimize way means use
TOP
Keyword, So the nth max and min salaries query as follows but the queries look like a tricky as in reverse order by using aggregate function names:N maximum salary:
for Ex: 3 maximum salary:
N minimum salary:
for Ex: 3 minimum salary:
To query the
nth highest bonus
, sayn=10
, using AdventureWorks2012, Try Following codeRefer following query for getting nth highest salary. By this way you get nth highest salary in MYSQL. If you want get nth lowest salary only you need to replace DESC by ASC in the query.