MYSQL从每个部门查找最大值

时间:2013-09-10 21:22:53

标签: mysql sql

我有一张这样的表

employeeid | departmentid | bossid | name | salary

我需要找到最高薪水,但是对于每个不同的离职人员。

4 个答案:

答案 0 :(得分:0)

GROUP BY与汇总功能MAX()一起使用:

SELECT MAX(salary), departmentid FROM your_table GROUP BY departmentid;

答案 1 :(得分:0)

您可以使用group by子句围绕departmentid构建一个组。对于该组,您可以使用聚合函数对每个组的数据运行操作,如max()

select departmentid,
       max(salary) as max_sal
from employees
group by departmentid

答案 2 :(得分:0)

您需要使用MAXGroup By

SELECT DepartmentId, MAX(SALARY) AS Salary
FROM EmployeesTable
GROUP BY DepartmentId

答案 3 :(得分:0)

select departmentid,  max(salary) as salary
from yourtab
group by departmentid