Sql 使用连接和where更新值
我尝试了以下命令:Sql 使用连接和where更新值,sql,postgresql,sql-update,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; 但是,我发现这是
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%,但我必须加入staff and Branch表以获取分支机构的位置。您的查询转换为正确的联接语法:
UPDATE staff s
SET salary = (salary * 1.1)
FROM branch b
WHERE b.city = 'London'
AND s.branchno = b.branchno;
这样可以避免报告的错误 您想要加入-请参阅
更新。。。FROM…
我上一次尝试了这一点,但无法通过FROM=/:更新员工工资加入s.branchno=b.branchno上的分支机构b,其中b.city='London'设置工资=工资*1.1;非常感谢。很有意义XD