56,678
社区成员
发帖
与我相关
我的任务
分享
mysql> delete from t1 where username='hx11';
Query OK, 2 rows affected (0.06 sec)
mysql> select * from t1;
+----------+--------+---------+--------+
| username | pageid | company | branch |
+----------+--------+---------+--------+
| ht10 | 001 | xxn | ht10 |
| ht10 | 002 | xin | hb10 |
+----------+--------+---------+--------+
2 rows in set (0.00 sec)
mysql> insert into t1
-> select 'hx11',pageid,company,branch from t1 where username='ht10';
Query OK, 2 rows affected (0.06 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from t1;
+----------+--------+---------+--------+
| username | pageid | company | branch |
+----------+--------+---------+--------+
| ht10 | 001 | xxn | ht10 |
| ht10 | 002 | xin | hb10 |
| hx11 | 001 | xxn | ht10 |
| hx11 | 002 | xin | hb10 |
+----------+--------+---------+--------+
4 rows in set (0.00 sec)
mysql>
mysql> select * from t1;
+----------+--------+---------+--------+
| username | pageid | company | branch |
+----------+--------+---------+--------+
| ht10 | 001 | xxn | ht10 |
| ht10 | 002 | xin | hb10 |
| hx11 | 001 | xin | hs10 |
| hx11 | 002 | xxn | ht10 |
+----------+--------+---------+--------+
4 rows in set (0.00 sec)
mysql> update t1 a,t1 b
-> set a.company=b.company,
-> a.branch=b.branch
-> where a.username='hx11'
-> and b.username='ht10'
-> and a.pageid=b.pageid;
Query OK, 2 rows affected (0.06 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select * from t1;
+----------+--------+---------+--------+
| username | pageid | company | branch |
+----------+--------+---------+--------+
| ht10 | 001 | xxn | ht10 |
| ht10 | 002 | xin | hb10 |
| hx11 | 001 | xxn | ht10 |
| hx11 | 002 | xin | hb10 |
+----------+--------+---------+--------+
4 rows in set (0.00 sec)
mysql>