我有两张表,
一张表是 User_id 和 name
第二张有 user_id 和 score
我现在要根据 name 查询得到 user_id
再按 user_id 来更新 score ,即update 语句。
能不能一次实现呢?即将查询嵌套在 update 语句里头呢?谢谢。
------解决方案--------------------
- SQL code
update t2 set t2.score=?from t1 where t2.[user_id]=t1.[user_id] and t1.name = 'xxx'
------解决方案--------------------
- SQL code
update 第二张表 set score=[yourvalue]where [user_id]=(select top 1 [user_id] from 第一张表 where [name]='yourname')
------解决方案--------------------
- SQL code
udpate aset a.score=分数from a inner join b a.id=b.id where b.name='名字'