84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
employee表的全部数据:
SELECT EMPLOYEE_id,salary,avg(salary) FROM test1.employees group by employee_idhaving avg(salary)>8000;
使用这个查询语句想得到平均工资大于8000的平均工资,可是为什么结果不是平均工资呢?
学习是最好的投资!
因为你group by id,每个id下不是只有一个工资么
select EMPLOYEE_id,salary,(select avg(salary) FROM employees) from employees where salary > (select avg(salary) FROM employees);
大概可以,你试试看吧
你是按照employee_id分组的,表记录里面每个employee_id就只有一条记录,你avg不就只有一个值吗.你如果想要全部员工的平均工资就不要groupb by了
理解有问题,平均工资,平均的什么呢,如果是针对employee_id的话,一个人的工资怎么能说平均工资呢。一般来说是某个部门下平均工资大于8000的员工工资吧
select t.salary,t.employee_id,t1.avg_salary from employees t inner join (select department_id,avg(salary) avg_salary from employees group by department_id) t1 on t.department_id = t1.department and t1.avg_salary > 8000
因为你group by id,每个id下不是只有一个工资么
大概可以,你试试看吧
你是按照employee_id分组的,表记录里面每个employee_id就只有一条记录,你avg不就只有一个值吗.
你如果想要全部员工的平均工资就不要groupb by了
理解有问题,平均工资,平均的什么呢,如果是针对employee_id的话,一个人的工资怎么能说平均工资呢。一般来说是某个部门下平均工资大于8000的员工工资吧
select t.salary,t.employee_id,t1.avg_salary from employees t inner join (select department_id,avg(salary) avg_salary from employees group by department_id) t1 on t.department_id = t1.department and t1.avg_salary > 8000