请帮我从sql中选择如何更新

时间:2014-09-02 15:33:51

标签: mysql sql sql-server

update employees set salary=salary*10/100+salary
where EmployeeID (select EmployeeID from employees where salary<2000)

1 个答案:

答案 0 :(得分:1)

尝试IN

update employees set salary=salary*10/100+salary
where EmployeeID IN (select EmployeeID from employees where salary<2000)

根据Lamak的建议

update employees set salary=salary*10/100+salary
where salary<2000

另一种选择。

update employees e1 set salary=salary*10/100+salary
where EXISTS (select NULL 
              from employees e2 
              where e2.salary<2000 
                and e1.EmployeeID = e2.EmployeeID
             )  

EXISTS在您的情况下是过度杀伤,但可能非常有用。 You should read about it. here's a good start :-)

在您的情况下,您应该只使用WHERE子句中的条件salary<2000