我与(emp_id,emp_name,salary)
等属性有员工关系,我想找到每个员工的薪水和平均工资之间的差异。我正在使用SQL Plus。
即。每个salary-avg(salary)
答案 0 :(得分:0)
试试这个。
SELECT a.emp_id,
a.emp_name,
a.salary,
a.Designation,
(a.salary - b.salary) as salary_difference
FROM employee AS a
INNER JOIN (
SELECT Designation, avg(salary) as salary
from employee
group by Designation) as b
ON a.Designation = b.Designation ;
答案 1 :(得分:0)
这可以使用窗口函数来完成:
SELECT emp_id,
emp_name,
salary
salary - avg(salary) over () as diff
FROM employee