MySQL与SqlServer中update操作同一个表问题

时间:2014-07-16 22:53:18   收藏:0   阅读:175

一 SqlServer中操作如下图

bubuko.com,布布扣

这个是没问题的。

二 MySQL中操作如下图

但是在MySQL中想实现这个功能如下图,但是出错了。

bubuko.com,布布扣

原来是MySQL中不支持子查询的

我们可以这样修改一下就可以实现它

bubuko.com,布布扣

看到没有,我仅仅在查询外面加了一层而已,却实现了。

代码如下:

create PROCEDURE testp(in _id int)
begin
  -- set @tt=(select id from usera where id>_id );
 update  usera set `names`=woaini where id in(select t.id from (select s.id from usera s where s.id>_id )t);
end 
call testp(2)

DROP PROCEDURE testp

select  * from  usera

MySQL与SqlServer的区别,需要慢慢发现。

 

MySQL与SqlServer中update操作同一个表问题,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!