ORACLE SQL:JOINS,AGGREGATES,SUBQUERIES

时间:2015-04-19 03:43:16

标签: sql oracle

所有员工都会显示部门编号,员工编号,员工姓名,工资以及每个部门的平均工资。

请帮忙!

2 个答案:

答案 0 :(得分:0)

select department_number, employee_number, employee_name, salary, 
(select AVG(salary) from employee B where A.department_number = B.department_number)
from employees A

假设您有类似的列名

答案 1 :(得分:0)

analytic version of the AVG() function非常适合这个:

select department_number
       , employee_number
       , employee_name
       , salary
       , AVG(salary) OVER (PARTITION BY department_number) 
                 as dept_avg_sal
from employee
order by department_number
       , employee_number
/

分析功能非常整洁。 Find out more