我是SQL的新手,我正在尝试执行以下操作:
update the salary of employees with their department avg salary.
我正在尝试SQL命令here。
我正在尝试的命令是:
update emp set sal = select avg(sal) from emp;
但我收到的错误是这样的:
ORA-00936: missing expression : update emp set sal = select avg(sal) from emp
我犯了错误?
提前致谢。
答案 0 :(得分:1)
update emp
set sal = (SELECT av FROM (SELECT AVG(sal) av FROM emp) s)
from emp;
答案 1 :(得分:1)
你所尝试的只是正确的...一般来说,子查询应该保留在括号内,只需尝试这个:update emp set sal = (select avg(sal) from emp);