【发布时间】:2011-09-11 22:31:17
【问题描述】:
我需要一些有关 oracle sql 的帮助。问题:我有 2 张表员工和部门。我从一个查询中得到了部门的平均工资,我想用它来看看有多少员工比他们部门的平均工资多。到目前为止我有这个。
此查询返回部门的平均值:
select ROUND(AVG(Salary), 2) Dept_avg_sal
from employee, department
where department.department_id = employee.department_id
group by department_name
我想做的是:
select employee_name,
salary,
d.department_name
from employee e,
department d
where salary > (select ROUND(AVG(Salary), 2) Dept_avg_sal
from employee,
department
where department.department_id = employee.department_id
group by department_name)
我得到的错误是:01427。 00000 - “单行子查询返回多于一行”
我知道同一部门的 2 名员工的收入高于平均水平,我认为这就是造成问题的原因。
EMPLOYEE_NAME - SALARY - -DEPARTMENT_NAME- DEPT_AVG_SAL
-------------------- ---------------------- -------------------- ------------
FISHER - 3000.00 - SALES - 2500.00
JONES - 3000.00 - ACCOUNTING - 2750.00
KING - 5000.00 - EXECUTIVE - 4500.00
**SCOTT - 2500.00 - IT - 2100.00
SMITH - 2900.00 - IT - 2100.00**
WILSON - 3000.00 - RESEARCH - 2633.33
任何帮助将不胜感激。
【问题讨论】:
-
你为什么要标记这个
MySQL你需要一个适用于 Oracle 和 MySQL 的答案吗?