Update statement with Aggregate function
Hi All,
I would like to update the records with sum of SAL+COMM+DEPTNO into SALCOMDEPT column for each row. Can we use SUM function in Update statement. Please help me out this
See below:
Table
CREATE TABLE EMP
(
EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10 CHAR),
JOB VARCHAR2(9 CHAR),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2),
SALCOMDEPT NUMBER
)
Used update statement :
UPDATE emp e1
SET e1.salcomdept= (select sum(sumsal+comm+deptno) from emp e2 where e2.empno=e1.empno)
WHERE e1.deptno = 10
commit
Thanks,
User