I am trying to get the maximum average salary and i am using this:
select max (avg_salary)
from (select name, avg(salary) AS avg_salary
from employee
group by name);
But is another way to get same result without using subquery?
I am trying to get the maximum average salary and i am using this:
select max (avg_salary)
from (select name, avg(salary) AS avg_salary
from employee
group by name);
But is another way to get same result without using subquery?
SELECT AVG(salary)
FROM employee
GROUP BY name
ORDER BY AVG(salary) DESC
LIMIT 1
One other option would be:
SELECT name, avg(salary) AS avg_salary
FROM employee
GROUP BY name
ORDER BY 2 DESC LIMIT 1;
Use this instead
SELECT name,
avg(salary) AS avg_salary
FROM employee
GROUP BY name
ORDER BY DESC avg_salary
LIMIT 1
Try this... this sort desc of avg salary then apply limit
SELECT AVG(salary),name
FROM employee GROUP BY name
ORDER BY AVG(salary) DESC
LIMIT 1
All employees:
SELECT name,
AVG(salary) AS avg_salary
FROM employee
GROUP BY name
ORDER BY avg_salary DESC
Maximum of one employee:
SELECT name,
AVG(salary) AS avg_salary
FROM employee
GROUP BY name
ORDER BY avg_salary DESC
LIMIT 1