码迷,mamicode.com
首页 > 数据库 > 详细

mysql同时修改2个表思路

时间:2015-01-13 19:22:13      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

1.需求:修改评论表中的昵称为手机号码最后4位。

UPDATE trans_eval SET issuer_name = MID(issuer_name,4,6) WHERE CHAR_LENGTH(issuer_name) = 11 AND issuer_name LIKE 1%;

2.由于误操作(MID(issuer_name,4,6)是中间的6位),需要数据回滚。

3.建立中间表(AND 1<>1 条件不符合建立空表)

CREATE TABLE tmp 
SELECT T2.REG_NO,T2.MOBILE,t1.`issuer_name`  FROM trans_eval  t1,member t2 WHERE t1.issuer_no =t2.`reg_no`  
 AND  MID(t2.`mobile`,4,6) =t1.`issuer_name`  AND 1<>1 GROUP BY T2.REG_NO,T2.MOBILE,t1.`issuer_name` ;

4.导入数据到中间表

INSERT INTO tmp 
SELECT T2.REG_NO,T2.MOBILE,t1.`issuer_name`  FROM trans_eval  t1,member t2 WHERE t1.issuer_no =t2.`reg_no`  
 AND  MID(t2.`mobile`,4,6) =t1.`issuer_name`  GROUP BY T2.REG_NO,T2.MOBILE,t1.`issuer_name` ;

5.数据恢复

SELECT * FROM tmp;
UPDATE tmp t1,trans_eval t2 SET t2.`issuer_name`=t1.`MOBILE` WHERE t1.`REG_NO`=t2.`issuer_no`;

 

mysql同时修改2个表思路

标签:

原文地址:http://www.cnblogs.com/simpledev/p/4221957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!