一个简单的Update语句
编程技术  /  houtizong 发布于 3年前   76
一个简单的Update语句
mysql> create table aa(name varchar(100),grade int(5));
Query OK, 0 rows affected (0.09 sec)
mysql> create table bb(name varchar(100),age int(5));
Query OK, 0 rows affected (0.14 sec)
mysql> insert into aa values('AAA',80);
Query OK, 1 row affected (0.05 sec)
mysql> insert into aa values('BBB',60);
Query OK, 1 row affected (0.06 sec)
mysql> insert into aa values('CCC',60);
Query OK, 1 row affected (0.03 sec)
mysql> insert into bb values('CCC',26);
Query OK, 1 row affected (0.05 sec)
mysql> insert into bb values('BBB',24);
Query OK, 1 row affected (0.03 sec)
mysql> insert into bb values('AAA',26);
Query OK, 1 row affected (0.03 sec)
mysql> select * from aa;
+------+-------+
| name | grade |
+------+-------+
| AAA | 80 |
| BBB | 60 |
| CCC | 60 |
+------+-------+
3 rows in set (0.00 sec)
mysql> select * from bb;
+------+------+
| name | age |
+------+------+
| CCC | 26 |
| BBB | 24 |
| AAA | 26 |
+------+------+
3 rows in set (0.00 sec)
--用aa表的grade更新bb表的age
mysql> update bb b set age=(select grade from aa a where a.name=b.name);
Query OK, 3 rows affected (0.03 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select * from bb;
+------+------+
| name | age |
+------+------+
| CCC | 60 |
| BBB | 60 |
| AAA | 80 |
+------+------+
3 rows in set (0.00 sec)
mysql>
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接