首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

某表的字段,更具另一张表开展更新

2013-01-28 
某表的字段,更具另一张表进行更新例如表UserIDNameDepTeam1A112B12现在有某个表CostIDUserIDdepteamcost 1

某表的字段,更具另一张表进行更新
例如表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

热点排行
Bad Request.