我有两张桌子。
部门(表)
DEPTID NUMBER(38)
NAME CHAR(20)
RANK NUMBER(38)
员工(表)
EMPID NUMBER(38)
DEPTID NUMBER(38)
NAME CHAR(40)
AGE NUMBER(38)
SALARY NUMBER(38)
我正在尝试运行以下查询,这会不断抛出错误。 查询是根据每个部门员工的平均年龄更新部门表中的排名。
UPDATE d
SET d.rank = T.rank
FROM department d
INNER JOIN
(SELECT
rownum as rank, age, deptId
FROM
(SELECT
AVG(age) AS age, deptid
FROM employee
GROUP by deptId
ORDER BY age DESC)) AS T ON T.deptId = d.deptId;