Update with correlated subquery
SQL
Medium
3 views
Problem Description
Update Employees set salary to department average salary for employees who have salary NULL.
Output Format
DML statement(s)
Constraints
Assume salary nullable
Official Solution
UPDATE Employees e SET salary = (SELECT AVG(salary) FROM Employees x WHERE x.dept_id = e.dept_id) WHERE e.salary IS NULL;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!