我想选择一名员工并将他/她的薪水增加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的问题。 任何人都能说出来吗?
答案 0 :(得分: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
答案 1 :(得分:0)
我无法在选择查询中添加列
首先添加一个新列来存储float数据类型的增加的工资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