[英]How do I get the Average of maximum value?
I have a SQL server problem where i have to get the average of the maximum salaries in each department.我有一个 SQL 服务器问题,我必须获得每个部门最高工资的平均值。 For example I have a department with id 1 that has an employee with a maximum salary of 50000, and a department with id 2 that has an employee with a maximum salary of 30000, what i have to do is calculate the average between these 2. What I tried:例如,我有一个 id 为 1 的部门,其员工的最高薪水为 50000,而一个 id 为 2 的部门,其员工的最高薪水为 30000,我要做的是计算这 2 个之间的平均值。我尝试了什么:
SELECT AVG(MAX(salary))
FROM employees
GROUP BY department_id
most simple think you can do is (if in the employee table, you have a department_id):最简单的想法是(如果在 employee 表中,你有一个 department_id):
SELECT AVG(p.maximum)
FROM (SELECT department_id, MAX(salary) AS maximum
FROM employees
GROUP BY department_id) p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.