我有一张这样的桌子
employeeid | departmentid | bossid | name | salary
我需要找到最高工资,但对于每个不同的部门ID。
您可以使用该group by
子句围绕departmentid
. 对于该组,您可以使用聚合函数对每个组的数据运行操作,例如max()
select departmentid,
max(salary) as max_sal
from employees
group by departmentid
select departmentid, max(salary) as salary
from yourtab
group by departmentid