表名 - Emlpoyee
Emp_id,Emp_name,地址,专业领域
表名 - Pallocation
Emp_id,PROJECT_ID,STAFF_COST
表名 - 项目
PROJECT_ID,Project_name,客户端
问)将电视广告项目中Kayleigh Donald PALLOCATION的员工成本从900改为1200
(我不认为有必要在表格中写下所有相关数据,我猜......?)
答案 0 :(得分:1)
试试这个...对于SQL Server 2012
update Pallocation
set Staff_Cost = 1200
from Employee emp
join Pallocation palloc
on emp.Emp_id = palloc.palloc
join Projects pro
on pro.PROJECT_ID = palloc.PROJECT_ID
where emp.Emp_name = 'Kayleigh Donald'
and pro.Project_name = 'TV ad project'
答案 1 :(得分:1)
此链接可能会对您有所帮助。
MySQL的 - (http://www.mysqltutorial.org/mysql-update-join/)
的Sql - (http://sqlandme.com/2013/06/18/sql-server-update-table-with-inner-join/)
答案 2 :(得分:0)
是否在练习中指定您需要使用连接? 否则,您可以使用子查询来解决此问题。
UPDATE Pallocation SET STAFF_COST = 1200
WHERE Emp_id = (SELECT Emp_id FROM Employee WHERE Emp_name = "Kayleigh Donald")
AND PROJECT_ID = (SELECT PROJECT_ID FROM Projects WHERE Project_name = "TV")
但Stackoverflow并不是要解决你的行为问题...... 你必须至少自己尝试并告诉我们你有多远。
答案 3 :(得分:0)
在SQL-SERVER
中应该是这样的:
UPDATE pa
SET pa.STAFF_COST = 1200
FROM Pallocation pa
JOIN Emlpoyee e
ON e.Emp_id = pa.Emp_id
JOIN Projects pr
ON pr.PROJECT_ID = pa.PROJECT_ID
WHERE pr.Client = 'Kayleigh Donald' AND pr.Project_Name = 'TV ad'