日期:2014-05-19  浏览次数:20492 次

高手救命啊~~~进来看看一个替换值的问题~~
update   hyclub   set   rightNumber=0   where   not   exists(select   *   from   hyclub   where   hynumber=rightNumber)

查询rightNumber,如果在hynumber里不存在,那么set   rightNumber=0

这样写怎么错了?

------解决方案--------------------
update hyclub set rightNumber=0 where hynumber <> rightNumber
------解决方案--------------------
update a set rightNumber=0
from hyclub a
where not exists(select * from hyclub where hynumber=a.rightNumber)


------解决方案--------------------
not exists(select * from hyclub where hynumber=rightNumber)
这样写,exists里面的与外面的没有连系.
要指定rightNumber 是外面的就对了..
------解决方案--------------------
你的语句相当于

update a set rightNumber=0
from hyclub a
where not exists(select * from hyclub b where b.hynumber=b.rightNumber)

你要求的是:

update a set rightNumber=0
from hyclub a
where not exists(select * from hyclub b where b.hynumber=a.rightNumber)


------解决方案--------------------
update hyclub set rightNumber=0 where not exists(select * from hyclub A where A.hynumber=rightNumber)
------解决方案--------------------
update hyclub set rightNumber=0 from hyclub A where not exists
(select * from hyclub B B.hynumber=A.rightNumber)
------解决方案--------------------
update a set rightNumber=0
from hyclub a
where not exists(select * from hyclub where hynumber=a.rightNumber)

和update hyclub set rightNumber=0 where hynumber <> rightNumber

是一样的查询结果,,,是同一个表,其实用后面的语句快些吧~~~