-1

我想选择一名员工并将他/她的工资提高 9.5% 并将更改保存在数据库中

查询如下..我在 SQL server 2008 中使用了两个相关的表 Employee_Tbl 和 Job_Tbl

SELECT  Employee_Tbl.EmployeeID, 
        Employee_Tbl.Salary,(Employee_Tbl.Salary*5/100)+Employee_Tbl.Salary as       
        SalaryIncreaseByFivePercent
FROM    Employee_Tbl INNER JOIN
                         Job_Tbl ON Employee_Tbl.JobTitle = Job_Tbl.JobTitle

我面临使用相同查询在数据库中保存额外列 SalaryIncreaseByFivePercent 的问题。有没有人可以告诉??

4

2 回答 2

0

你想在UPDATE这里使用和声明。像下面这样的东西可以解决问题

UPDATE Emplotee_Tbl 
SET Employee_Tbl.Salary = (Employee_Tbl.Salary*5/100) + Employee_Tbl.Salary 
FROM Employee_Tbl AS et 
    INNER JOIN Job_Tbl AS jt 
        ON et.JobTitle = jt.JobTitle 
WHERE Employee_Tbl.EmployeeLastName = "Burns";
GO 

我希望这有帮助。


编辑。要创建一个名为的新列SalaryIncreaseByFivePercent并在其中插入更新后的薪水,您只需使用创建新列

ALTER TABLE table_name
ADD column_name datatype;
GO
于 2013-04-16T08:42:17.490 回答
0

我不可能在选择查询中添加一列

首先添加一个新列来存储浮动数据类型的增加薪水increasedSalary

ALTER TABLE Employee_Tbl
ADD increasedSalary float

然后更新表

UPDATE Emplotee_Tbl 
SET increasedSalary = (Employee_Tbl.Salary*5/100) + Employee_Tbl.Salary
FROM Employee_Tbl  t 
   INNER JOIN Job_Tbl  j 
ON t.JobTitle = j.JobTitle 
于 2013-04-16T08:56:20.970 回答