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