84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
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