在T-SQL中使用标准

时间:2012-09-14 03:53:42

标签: sql tsql

好的,我搜遍了许多不同的地方,不幸的是它可能更容易提问,

我必须选择一些数据然后将薪水设置增加10%,其中我的标准是在另一个表上这是我的代码

 Select E.Lastname, E.Salary, J.EEO1Classification from Employee as E
 Join JobTitle as J
 on E.JobTitleID = J.JobTitleID 
 Update Employee
 set Salary = (Salary * .10) + Salary
 where [JobTitle.EEO1Classification] = 'Office/Clerical'

我哪里错了?

2 个答案:

答案 0 :(得分:2)

UPDATE Employee e
SET e.Salary = e.Salary * 1.1
WHERE e.JobTitleID IN 
( SELECT j.JobTitleID FROM JobTitle j 
        WHERE j.EEO1Classification = 'Office/Clerical'
)

答案 1 :(得分:0)

我认为这是你可能想要实现的目标。基本上UPDATE使用JOINJobTitle

MySQL

UPDATE Employee E
INNER JOIN JobTitle as J
  ON E.JobTitleID = J.JobTitleID 
SET Salary = (Salary * .10) + Salary
WHERE [J.EEO1Classification] = 'Office/Clerical'

替代语法

UPDATE
    e
SET
    Salary = (Salary * .10) + Salary
FROM
    Employee E
    JOIN
    JobTitle J ON E.JobTitleID = J.JobTitleID 
WHERE
    J.EEO1Classification = 'Office/Clerical'