使用连接和位置更新值

时间:2014-03-28 03:10:13

标签: sql postgresql sql-update

我尝试过以下命令:

UPDATE staff SET salary = (salary * 1.1)
where branchno = (select branchno from branch where city = 'London');

update salary from staff s join branch b on s.branchno = b.branchno
where b.city = 'London' set salary = salary * 1.1;

但是,我将此作为错误回复:

> ERROR:  more than one row returned by a subquery used as an expression

有什么想法吗?基本上我想更新所有员工工资的成员在伦敦生活的10%,但我必须加入员工和分支表来获得分支机构的位置。

1 个答案:

答案 0 :(得分:1)

您的查询转换为正确的连接语法:

UPDATE staff s
SET    salary = (salary * 1.1)
FROM   branch b
WHERE  b.city = 'London'
AND    s.branchno = b.branchno;

这可以避免报告的错误。 The manual has more on UPDATE.