在sql中找到最大平均值

时间:2013-11-20 10:18:11

标签: php mysql sql

我正在努力获得最高平均工资,我正在使用它:

select max (avg_salary)
from (select name, avg(salary) AS avg_salary
  from employee
  group by name);

但是在不使用子查询的情况下获得相同结果的另一种方法是什么?

5 个答案:

答案 0 :(得分:2)

SELECT AVG(salary)
FROM employee
GROUP BY name
ORDER BY AVG(salary) DESC
LIMIT 1

答案 1 :(得分:1)

另一个选择是:

SELECT name, avg(salary) AS avg_salary
FROM employee
GROUP BY name
ORDER BY 2 DESC LIMIT 1;

答案 2 :(得分:0)

改为使用

SELECT name, 
       avg(salary) AS avg_salary   
FROM employee 
GROUP BY name 
ORDER BY DESC avg_salary 
      LIMIT 1

答案 3 :(得分:0)

试试这个...这种平均工资desc然后适用限制

SELECT AVG(salary),name
FROM employee GROUP BY name
ORDER BY AVG(salary) DESC
LIMIT 1

答案 4 :(得分:0)

所有员工:

SELECT name, 
       AVG(salary) AS avg_salary 
FROM employee 
GROUP BY name 
ORDER BY avg_salary DESC

最多一名员工:

SELECT name, 
AVG(salary) AS avg_salary 
FROM employee 
GROUP BY name 
ORDER BY avg_salary DESC 
LIMIT 1