Is there a command akin to:
2nd highest salary from tbl_salary
or
4th highest salary from tbl_salary
?
I've seen:
select salary
from tbl_salary t
where &n = (
select count(salary)
from(
select distinct salary
from tbl_salary
)where t.salary<=salary
);
How does this it works?
Are there other simple ways to get result?
Here is a way to do this task using dense_rank() function. Query : select * from( select ename, sal, dense_rank() over(order by sal desc)r from Employee) where r=&n; To find to the 2nd highest sal set n = 2 To find 3rd highest sal set n = 3 and so on.
select column_name from table_name order by column_name desc limit n-1,1; where n = 1, 2, 3,.... nth max value.
The LARGE function is an easy way to get the nth largest value in a range: = LARGE ( range , 1 ) // 1st largest = LARGE ( range , 2 ) // 2nd largest = LARGE ( range , 3 ) // 3rd largest In this example, we can use the LARGE function to get a highest...
select * from employee order by salary desc limit 1,1
Description : limit x,y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With