读书人

SQL 语句怎么在 能不能在where 里嵌

发布时间: 2012-09-23 10:28:11 作者: rapoo

SQL 语句,如何在 能不能在where 里嵌套查询?
我有两张表,
一张表是 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='名字' 

读书人网 >SQL Server

热点推荐