我是 SQL 新手,但我被查询困住了。
我有 3 个表员工、部门和工资。 我正在尝试通过给出此条件来更新工资表中的奖金列
give 10% bonus on total salary to the employees who are not in IT departments.
我想出了这个查询
update salary_paid
set bonus=(select (0.1*total_salary) "Bonus"
from salary_paid, departments, employees
where
employees.department_id=departments.department_id and
employees.employee_id=salary_paid.employee_id and
departments.department_name!='IT')
;
但是它返回此错误
ORA-01427: single-row subquery returns more than one row
我对此一无所知,请帮忙。 提前致谢
最佳答案
您的内部查询(select (0.1*total_salary) "Bonus"from salary_paid
返回多个值,因此无法分配给奖金列。
尝试使用这样的连接进行更新
UPDATE
(SELECT salary_paid.bonus as oldBonus, 0.1*salary_paid.total_salary as newBounus
FROM salary_paid
INNER JOIN employees
ON salary_paid.employee_id = employees.employee_id
INNER JOIN departments
ON departments.department_id = employees.department_id
WHERE departments.department_name != 'IT'
) t
SET t.oldBonus= t.newBounus
关于mysql - 返回单行子查询的更新语句返回多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22602787/