在MySQL里,不可以修改同一个表并使用SELECT语句.详情查看http://dev.mysql.com/doc/mysql/en/UPDATE.html
可以选用JOIN来实现,例证如下
用SELECT的原语句:
update spms.user
set DirectReport=(select DirectReport from spms.user where
UserName='%s')
where UserName in (select UserName from spms.user where
DirectReport='%s')
选用JOIN来实现的语句:
update spms.user as u1
inner join spms.user as u2 on u1.DirectReport= u2.UserName
set u1.DirectReport=u2.DirectReport where u2.UserName='%s'
2014-07-13 16:21:43