Reputation: 523
select max(salary)
from employ
where salary < ( select max(salary)
from employ
having count(max(salary)>salary)=3);
Here I am trying to find out 4th max salary using aggregate function in aggregate function.It is showing an error Invalid use of group function.
What is wrong in it?please help
thank you.
Upvotes: 0
Views: 1694
Reputation: 1269445
The easiest way is to just use limit
:
select max(salary) as salary
from employ
order by salary desc
limit 3, 1;
Upvotes: 3
Reputation: 44581
No, you can't do that. Instead you can order by
salary
in the descending order, then limit
your result to 4 records and retrieve the minimum one:
select min(salary)
from ( select max(salary) as salary
from employ
order by salary desc
limit 4)
Upvotes: 2