sql - 查找每个成员超过五个的部门的平均工资
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9391356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sql - find average salary for each department with more than five members
提问by user1225281
Not quite sure how to get this one. I have a staff table and I need to find the average salary. I know I can use use avg()
. But the trick is I need to find the average for departments that have more than 5 staff members. I'm not sure if I should use group by or how to use it. Thanks!
不太确定如何获得这个。我有一张员工表,我需要找到平均工资。我知道我可以使用 use avg()
。但诀窍是我需要找到超过 5 名员工的部门的平均值。我不确定是否应该使用 group by 或如何使用它。谢谢!
CREATE TABLE STAFF (STAFF_ID CHAR(3),
STAFF_NAME CHAR(20),
GENDER CHAR(6),
DEPARTMENT CHAR(20),
BOSS_ID CHAR(3)
SALARY NUMBER(8,2));
回答by Vikram
select DEPARTMENT,count(STAFF_ID) as CountStaff, avg(SALARY) as AVGSalary
from STAFF
group by DEPARTMENT
having count(STAFF_ID) > 5