某表的字段,更具另一张表进行更新
例如表User
ID Name Dep Team
1 A 1 1
2 B 1 2
现在有某个表Cost
ID UserID dep team cost
1 1 2 2 100
2 2 1 1 100
如果按照User表的dep 和team来更新cost,这条sql如何写呢..?
谢谢
------解决方案--------------------update Cost
set dep=u.dep,Team=u.Team from User u where u.id=Cost.UserId
------解决方案--------------------update c set
dep = u.dep,team = u.team
from cost c,user u
where c.userid = u.id