我想将Department_name更新为deparment_name,并将'_1'(示例:Administration_1)更新为2,但这里是错误,请帮助正确书写答案。 错误:单行子查询返回多行
UPDATE departments
SET department_name= (SELECT department_name || '_1' from departments)
WHERE manager_id=
(select manager_id from employees
WHERE MOD( manager_id, 2) != 0);
答案 0 :(得分:0)
您可以尝试使用合并
MERGE INTO departments a
USING ( SELECT department_name || '_1' as name,
DEPARTMENT_ID from departments
WHERE manager_id in (
(select manager_id from employees
WHERE MOD( manager_id, 2) != 0)
)
) b
ON ( a.DEPARTMENT_ID = b.DEPARTMENT_ID )
WHEN MATCHED THEN
UPDATE SET a.department_name = b.name
答案 1 :(得分:0)
您正在尝试使用过多的行来更新单行(您的(从部门中选择SELECT department_name ||'_1')) 我认为您可以做到
SET department_name= department_name || '_1'
答案 2 :(得分:0)
您可以在下面尝试
UPDATE departments
SET department_name= SELECT department_name || '_1'
WHERE exists
(select employees.manager_id from employees where departments.manager_id =employees.manager_id
and MOD( employees.manager_id, 2) != 0)