当前位置: 首页 > news >正文

MySQL--表的基本查询--0410--15

目录

1. Create

1.1 insert

1.1.2 插入否则更新

1.2 replace

2.Retrieve

2.1 select

2.1.1 全列查询

2.1.2 指定列查询

2.1.3 查询字段为表达式

2.1.4 为查询结果指定名称

 2.1.5 去重

2.2 where

2.2.1  >  and >= and < and <= and =

2.2.2  in  between

2.2.3 查找列数值为null的方法

2.2.4 like 

2.2.5 where中使用表达式

2.3 结果排序

2.3.2 多级排序

2.3.3 显示多个或者有限个

2.3.4 补充

2.4 mysql中select语句的执行顺序

3. update

 3.1 更新数据

 4. delete操作

 4.1 delete

4.1.1 删除某一个数据

 4.1.2 删除整张表的数据

 4.2 truncate

 5.插入查询结果


表的操作,CRUD:create、retrieve、update、delete

1. Create

1.1 insert

语法

INSERT [INTO] table_name
[(column [, column] ...)]
VALUES (value_list) [, (value_list)] ..
  • into 可以不写
  • () values ()   左边的括号代表要对哪些数据进行显式的插入,左括号如果不写则默认对全部列进行插入,右边的括号表示具体的数值。
  • 如果要一次性插入多组数据,可以在一组数据插入完毕后,再跟一组右括号。
mysql> create table t10( id int unsigned primary key auto_increment,-> stu_num int not null unique,-> name varchar(10),-> qq varchar(20)-> );mysql> insert into t10 values (100,1,'steven','12345');mysql> insert into t10 (stu_num,name.qq) values (3,'kim','1234567');mysql> insert into t10 (stu_num,name,qq) values (5,'cat','56789'),('6','dog','7890');
mysql> select * from t10;
+-----+---------+--------+---------+
| id  | stu_num | name   | qq      |
+-----+---------+--------+---------+
| 100 |       1 | steven | 12345   |
| 101 |       2 | kim    | 1234567 |
| 102 |       3 | kim    | 1234567 |
| 103 |       4 | ketty  | 5678    |
| 104 |       5 | cat    | 56789   |
| 105 |       6 | dog    | 7890    |

如果列属性为主键或者唯一键,在插入时重复了怎么办?

1.1.2 插入否则更新

语法

INSERT ... ON DUPLICATE KEY UPDATE
column = value [, column = value] ...

其实可以理解为当写好了一个插入语句之后

加上 on duplicate key update 列名1=xx,列名2=xx;

-->表中 stu_num已经有一个是4的了mysql> insert into t10 (stu_num,name,qq) values (4,'sunnyboy','25679') on duplicate key update id=4,name='sunnyboy';
Query OK, 2 rows affected (0.00 sec)--> 如果冲突了 就把 id改成4 name改成sunnyboymysql> select * from t10;
+-----+---------+----------+---------+
| id  | stu_num | name     | qq      |
+-----+---------+----------+---------+
|   4 |       4 | sunnyboy | 5678    |
| 100 |       1 | steven   | 12345   |
| 101 |       2 | kim      | 1234567 |
| 102 |       3 | kim      | 1234567 |
| 104 |       5 | cat      | 56789   |
| 105 |       6 | dog      | 7890    |
+-----+---------+----------+---------+

 可以根据mysql的回显查看是不是有冲突

Query OK, 2 rows affected (0.47 sec)
-- 0 row affected: 表中有冲突数据,但冲突数据的值和 update 的值相等
-- 1 row affected: 表中没有冲突数据,数据被插入
-- 2 row affected: 表中有冲突数据,并且数据已经被更新

1.2 replace

使用和insert一模一样,只是

  • 主键或者唯一键没有冲突 则直接插入。
  • 逐渐或者唯一键有冲突,则删除后再插入。
mysql> replace into t10 values(106,7,'sam','2369');
Query OK, 1 row affected (0.01 sec)mysql> select * from t10;
+-----+---------+-----------+---------+
| id  | stu_num | name      | qq      |
+-----+---------+-----------+---------+
|   4 |       4 | sunnyboy  | 5678    |
| 105 |       6 | dog       | 7890    |
| 106 |       7 | sam       | 2369    |
+-----+---------+-----------+---------+mysql> replace into t10 values(106,7,'sam','123659');
mysql> select * from t10;
+-----+---------+-----------+---------+
| id  | stu_num | name      | qq      |
+-----+---------+-----------+---------+
|   4 |       4 | sunnyboy  | 5678    |
| 105 |       6 | dog       | 7890    |
| 106 |       7 | sam       | 123659  |
+-----+---------+-----------+---------+

2.Retrieve

Retrieve 依赖于 select,where,order by这些关键字。

2.1 select

语法

SELECT
[DISTINCT] {* | {column [, column] ...}          -->从哪列找
[FROM table_name]                                      -->从哪个表找
[WHERE ...]                                                  --> 约束条件是什么
[ORDER BY column [ASC | DESC], ...]
LIMIT ..

mysql> CREATE TABLE exam_result (-> id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,-> name VARCHAR(20) NOT NULL COMMENT '同学姓名',-> chinese float DEFAULT 0.0 COMMENT '语文成绩',-> math float DEFAULT 0.0 COMMENT '数学成绩',-> english float DEFAULT 0.0 COMMENT '英语成绩'-> );
Query OK, 0 rows affected (0.01 sec)mysql> INSERT INTO exam_result (name, chinese, math, english) VALUES-> ('唐三藏', 67, 98, 56),-> ('孙悟空', 87, 78, 77),-> ('猪悟能', 88, 98, 90),-> ('曹孟德', 82, 84, 67),-> ('刘玄德', 55, 85, 45),-> ('孙权', 70, 73, 78),-> ('宋公明', 75, 65, 30);

2.1.1 全列查询

mysql> select * from exam_result;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
|  2 | 孙悟空    |      87 |   78 |      77 |
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      82 |   84 |      67 |
|  5 | 刘玄德    |      55 |   85 |      45 |
|  6 | 孙权      |      70 |   73 |      78 |
|  7 | 宋公明    |      75 |   65 |      30 |
+----+-----------+---------+------+---------+

2.1.2 指定列查询

mysql> select id,name,math from exam_result;
+----+-----------+------+
| id | name      | math |
+----+-----------+------+
|  1 | 唐三藏    |   98 |
|  2 | 孙悟空    |   78 |
|  3 | 猪悟能    |   98 |
|  4 | 曹孟德    |   84 |
|  5 | 刘玄德    |   85 |
|  6 | 孙权      |   73 |
|  7 | 宋公明    |   65 |
+----+-----------+------+

2.1.3 查询字段为表达式

mysql> select id,name,math+10 from exam_result;
+----+-----------+---------+
| id | name      | math+10 |
+----+-----------+---------+
|  1 | 唐三藏    |     108 |
|  2 | 孙悟空    |      88 |
|  3 | 猪悟能    |     108 |
|  4 | 曹孟德    |      94 |
|  5 | 刘玄德    |      95 |
|  6 | 孙权      |      83 |
|  7 | 宋公明    |      75 |
+----+-----------+---------+
mysql> select id,name,math+chinese+english from exam_result;
+----+-----------+----------------------+
| id | name      | math+chinese+english |
+----+-----------+----------------------+
|  1 | 唐三藏    |                  221 |
|  2 | 孙悟空    |                  242 |
|  3 | 猪悟能    |                  276 |
|  4 | 曹孟德    |                  233 |
|  5 | 刘玄德    |                  185 |
|  6 | 孙权      |                  221 |
|  7 | 宋公明    |                  170 |
+----+-----------+----------------------+

2.1.4 为查询结果指定名称

mysql会根据表达式的内容直接成为列名,但是这样不方便。所以提供了as关键字

mysql> select id,name,math+chinese+english as total from exam_result;
+----+-----------+-------+
| id | name      | total |
+----+-----------+-------+
|  1 | 唐三藏    |   221 |
|  2 | 孙悟空    |   242 |
|  3 | 猪悟能    |   276 |
|  4 | 曹孟德    |   233 |
|  5 | 刘玄德    |   185 |
|  6 | 孙权      |   221 |
|  7 | 宋公明    |   170 |
+----+-----------+-------+把as省略也可以mysql> select id,name,math+chinese+english total from exam_result;
+----+-----------+-------+
| id | name      | total |
+----+-----------+-------+
|  1 | 唐三藏    |   221 |
|  2 | 孙悟空    |   242 |
|  3 | 猪悟能    |   276 |
|  4 | 曹孟德    |   233 |
|  5 | 刘玄德    |   185 |
|  6 | 孙权      |   221 |
|  7 | 宋公明    |   170 |
+----+-----------+-------+

 2.1.5 去重

distinct 关键字

exam_result中有两个数学成绩为98分的,如果需要去重查看则需要

mysql> select distinct math from exam_result;
+------+
| math |
+------+
|   98 |
|   78 |
|   84 |
|   85 |
|   73 |
|   65 |
+------+

2.2 where

where 用于筛选数据条件,可以用以下运算符进行修改数据选择范围。

>,>=,<=,<大小比较
=,<=>

等于,=不能用于比较NULL

<=>可以用于比较NULL

!=,<>不等于
between 0 and 100在[0,100]之中
in(xxx...)是否在括号内的内容当中

is null

is not null

是null

不是null

like

模糊匹配

like xx%   %表示任意多个任意字符

like xx_  _表示一个任意字符

and        多个条件表必须都为true
or任意一个条件为true
not

2.2.1  >  and >= and < and <= and =

mysql> select name,chinese from exam_result where chinese>70;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 孙悟空    |      87 |
| 猪悟能    |      88 |
| 曹孟德    |      82 |
| 宋公明    |      75 |
+-----------+---------+
mysql> select name,chinese from exam_result where chinese=70;
+--------+---------+
| name   | chinese |
+--------+---------+
| 孙权   |      70 |
+--------+---------+
mysql> select name,chinese from exam_result where chinese!=70;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 唐三藏    |      67 |
| 孙悟空    |      87 |
| 猪悟能    |      88 |
| 曹孟德    |      82 |
| 刘玄德    |      55 |
| 宋公明    |      75 |
+-----------+---------+

2.2.2  in  between

mysql> select 1 in (1,2,3,4,5);
+------------------+
| 1 in (1,2,3,4,5) |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)mysql> select 10 in (1,2,3,4,5);
+-------------------+
| 10 in (1,2,3,4,5) |
+-------------------+
|                 0 |
+-------------------+
1 row in set (0.00 sec)
mysql> select name,math from exam_result where math in (98,90,85,84);
+-----------+------+
| name      | math |
+-----------+------+
| 唐三藏    |   98 |
| 猪悟能    |   98 |
| 曹孟德    |   84 |
| 刘玄德    |   85 |
+-----------+------+
4 rows in set (0.00 sec)mysql> select name,math from exam_result where math between 84 and 98;
+-----------+------+
| name      | math |
+-----------+------+
| 唐三藏    |   98 |
| 猪悟能    |   98 |
| 曹孟德    |   84 |
| 刘玄德    |   85 |
+-----------+------+

2.2.3 查找列数值为null的方法

mysql> select * from 表名 where 列名<=>NULL;
mysql> select * from 表名 where 列名 is NULL;

2.2.4 like 

比如查找姓孙的同学,或者叫孙xx 或者 孙x的同学。

姓孙的条件比较宽松,不限制名字长度,适合使用%,

而孙xx或者孙x,不仅限制了姓,还限制了名字长度,就需要使用_

mysql> select name,math from exam_result where name like '孙%';
+-----------+------+
| name      | math |
+-----------+------+
| 孙悟空    |   78 |
| 孙权      |   73 |
+-----------+------+
2 rows in set (0.00 sec)mysql> select name,math from exam_result where name like '孙_';
+--------+------+
| name   | math |
+--------+------+
| 孙权   |   73 |
+--------+------+
1 row in set (0.00 sec)mysql> select name,math from exam_result where name like '孙__';
+-----------+------+
| name      | math |
+-----------+------+
| 孙悟空    |   78 |
+-----------+------+
1 row in set (0.00 sec)

2.2.5 where中使用表达式

  • WHERE 条件中使用表达式

-- 别名不能用在 WHERE 条件中   后面在总结mysql语句的执行顺序时会谈到

mysql> select id,name,chinese+math+english as total from exam_result;
+----+-----------+-------+
| id | name      | total |
+----+-----------+-------+
|  1 | 唐三藏    |   221 |
|  2 | 孙悟空    |   242 |
|  3 | 猪悟能    |   276 |
|  4 | 曹孟德    |   233 |
|  5 | 刘玄德    |   185 |
|  6 | 孙权      |   221 |
|  7 | 宋公明    |   170 |
+----+-----------+-------+
7 rows in set (0.00 sec)mysql> select id,name,chinese+math+english as total from exam_result where chinese+math+english>230;
+----+-----------+-------+
| id | name      | total |
+----+-----------+-------+
|  2 | 孙悟空    |   242 |
|  3 | 猪悟能    |   276 |
|  4 | 曹孟德    |   233 |
+----+-----------+-------+
3 rows in set (0.00 sec)mysql> select id,name,chinese+math+english as total from exam_result where total>230;
ERROR 1054 (42S22): Unknown column 'total' in 'where clause'
  • WHERE 条件中比较运算符两侧都是字段
mysql> select id,name,chinese,english from exam_result where chinese > english;
+----+-----------+---------+---------+
| id | name      | chinese | english |
+----+-----------+---------+---------+
|  1 | 唐三藏    |      67 |      56 |
|  2 | 孙悟空    |      87 |      77 |
|  4 | 曹孟德    |      82 |      67 |
|  5 | 刘玄德    |      55 |      45 |
|  7 | 宋公明    |      75 |      30 |
+----+-----------+---------+---------+
  •  and 和 not的使用

 查询语文成绩大于80 并且不姓孙的同学

mysql> select id,name,chinese from exam_result where chinese>80;
+----+-----------+---------+
| id | name      | chinese |
+----+-----------+---------+
|  2 | 孙悟空    |      87 |
|  3 | 猪悟能    |      88 |
|  4 | 曹孟德    |      82 |
+----+-----------+---------+
3 rows in set (0.00 sec)mysql> select id,name,chinese from exam_result where chinese>80 and name not like '孙%';
+----+-----------+---------+
| id | name      | chinese |
+----+-----------+---------+
|  3 | 猪悟能    |      88 |
|  4 | 曹孟德    |      82 |
+----+-----------+---------+
  • 综合查询

孙某同学,否则要求总成绩 > 200 并且 语文成绩 < 数学成绩 并且 英语成绩 > 80

mysql> select id,name,chinese+math+english as total from exam_result;
+----+-----------+-------+
| id | name      | total |
+----+-----------+-------+
|  1 | 唐三藏    |   221 |
|  2 | 孙悟空    |   242 |
|  3 | 猪悟能    |   276 |
|  4 | 曹孟德    |   233 |
|  5 | 刘玄德    |   185 |
|  6 | 孙权      |   221 |
|  7 | 宋公明    |   170 |
+----+-----------+-------+
mysql> select id,name,chinese+math+english as total from exam_result where name like '孙_' or (math+english+chinese>200 and chinese<math and english>80) ;
+----+-----------+-------+
| id | name      | total |
+----+-----------+-------+
|  3 | 猪悟能    |   276 |
|  6 | 孙权      |   221 |
+----+-----------+-------+

2.3 结果排序

asc为升序 desc为降序  默认为升序。 书写位置在筛选完成之后。

注意:null视为比任何元素都小。

SELECT ... FROM table_name [WHERE ...]
ORDER BY column [ASC|DESC], [...];mysql> select id,name,math from exam_result order by math asc;
+----+-----------+------+
| id | name      | math |
+----+-----------+------+
|  7 | 宋公明    |   65 |
|  6 | 孙权      |   73 |
|  2 | 孙悟空    |   78 |
|  4 | 曹孟德    |   84 |
|  5 | 刘玄德    |   85 |
|  1 | 唐三藏    |   98 |
|  3 | 猪悟能    |   98 |
+----+-----------+------+
7 rows in set (0.00 sec)mysql> select id,name,math from exam_result order by math desc;
+----+-----------+------+
| id | name      | math |
+----+-----------+------+
|  1 | 唐三藏    |   98 |
|  3 | 猪悟能    |   98 |
|  5 | 刘玄德    |   85 |
|  4 | 曹孟德    |   84 |
|  2 | 孙悟空    |   78 |
|  6 | 孙权      |   73 |
|  7 | 宋公明    |   65 |
+----+-----------+------+
mysql> select id,name,math from exam_result where math>80 order by math desc;
+----+-----------+------+
| id | name      | math |
+----+-----------+------+
|  1 | 唐三藏    |   98 |
|  3 | 猪悟能    |   98 |
|  5 | 刘玄德    |   85 |
|  4 | 曹孟德    |   84 |
+----+-----------+------+

2.3.2 多级排序

order by 后面跟的越近,排序时的优先级越高

数学成绩一样,那就按语文成绩来排。

注意每一项都需要带上desc 或者 asc 不然可能由于缺省为asc的原因导致排序不是理想结果。

mysql> select id,name,math,chinese from exam_result where math>80 order by math desc,chinese desc;
+----+-----------+------+---------+
| id | name      | math | chinese |
+----+-----------+------+---------+
|  3 | 猪悟能    |   98 |      88 |
|  1 | 唐三藏    |   98 |      67 |
|  5 | 刘玄德    |   85 |      55 |
|  4 | 曹孟德    |   84 |      82 |
+----+-----------+------+---------+
4 rows in set (0.00 sec)mysql> select id,name,math,chinese from exam_result where math>80 order by math desc,chinese asc;
+----+-----------+------+---------+
| id | name      | math | chinese |
+----+-----------+------+---------+
|  1 | 唐三藏    |   98 |      67 |
|  3 | 猪悟能    |   98 |      88 |
|  5 | 刘玄德    |   85 |      55 |
|  4 | 曹孟德    |   84 |      82 |
+----+-----------+------+---------+

2.3.3 显示多个或者有限个

order by后面可以跟上

  • limit 数字 以限制显示的个数
  • 也可以 limit s,n  

s表示从哪里开始 n表示要几个 

s为0表示从最大/小的 开始     s为1表示从第二大/小的开始

mysql> select id,name,math+chinese+english as grade from exam_result where chinese+math+english>210 order by grade asc;
+----+-----------+-------+
| id | name      | grade |
+----+-----------+-------+
|  1 | 唐三藏    |   221 |
|  6 | 孙权      |   221 |
|  4 | 曹孟德    |   233 |
|  2 | 孙悟空    |   242 |
|  3 | 猪悟能    |   276 |
+----+-----------+-------+
5 rows in set (0.00 sec)mysql> select id,name,math+chinese+english as grade from exam_result where chinese+math+english>210 order by grade asc limit 3;
+----+-----------+-------+
| id | name      | grade |
+----+-----------+-------+
|  1 | 唐三藏    |   221 |
|  6 | 孙权      |   221 |
|  4 | 曹孟德    |   233 |
+----+-----------+-------+

2.3.4 补充

order by也可以跟表达式 而且在order by中可以使用别名

mysql> select id,name,math+chinese as grade from exam_result where chinese+math>140 order by grade asc;
+----+-----------+-------+
| id | name      | grade |
+----+-----------+-------+
|  6 | 孙权      |   143 |
|  1 | 唐三藏    |   165 |
|  2 | 孙悟空    |   165 |
|  4 | 曹孟德    |   166 |
|  3 | 猪悟能    |   186 |
+----+-----------+-------+

2.4 mysql中select语句的执行顺序

首先,mysql在执行select语句时,一定首先要知道在哪个表里取数据。from语句一定是首先执行的。然后如果有where语句,mysql就会把在条件外的数据筛掉。然后根据select 后面跟的列名,把表的数据显示到屏幕上。

  • 所以如果重命名是在where语句之后进行的,where语句从哪里知道这个别名呢?这也就是为什么where语句中不能使用别名的原因。
  • 如果是order by,我们既然已经开始对数据进行排序了。那么首先是不是我们已经拿到了数据,也就是没有排序之前的数据,那这个时候,重命名已经执行好了,order by语句中是可以认识这个别名的,所以也就可以使用别名。
  • group by 的意思是根据组别先筛选出一些数据,不是该类别的不要。那他的执行顺序是不是按理来说比where更早呢?因为如果先执行where,会将一部分我不要的数据也筛选进来。

3. update

update操作依赖于update关键字

UPDATE table_name SET column = expr [, column = expr ...]
[WHERE ...] [ORDER BY ...] [LIMIT ...]

 3.1 更新数据

  • 更新一下数学成绩
mysql> select * from exam_result where name='曹孟德';
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  4 | 曹孟德    |      82 |   84 |      67 |
+----+-----------+---------+------+---------+
1 row in set (0.00 sec)mysql> update exam_result set math=90 where name='曹孟德';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> select * from exam_result where name='曹孟德';
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  4 | 曹孟德    |      82 |   90 |      67 |
+----+-----------+---------+------+---------+
  • 可以一次性多次修改

mysql> update exam_result set math=90,chinese=80 where name='曹孟德';

  •  综合筛选条件进行修改

将总成绩倒数前三的 3 位同学的数学成绩加上 30 分

mysql> select id,name,chinese+math+english as total from exam_result order by total asc limit 3;
+----+-----------+-------+
| id | name      | total |
+----+-----------+-------+
|  7 | 宋公明    |   170 |
|  5 | 刘玄德    |   185 |
|  1 | 唐三藏    |   221 |
+----+-----------+-------+
3 rows in set (0.00 sec)mysql> update exam_result set math=math+30 order by chinese+math+english limit 3;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0mysql> select id,name,chinese+math+english as total from exam_result order by total asc limit 3;
+----+-----------+-------+
| id | name      | total |
+----+-----------+-------+
|  7 | 宋公明    |   200 |
|  5 | 刘玄德    |   215 |
|  6 | 孙权      |   221 |
+----+-----------+-------+
  • 注意没有where 或者 order by limit语句 update会更新全表的内容
     

 4. delete操作

delete操作依赖于delete关键字  和 truncate 关键字

DELETE FROM table_name [WHERE ...] [ORDER BY ...] [LIMIT ...]     

 4.1 delete

4.1.1 删除某一个数据

mysql> DELETE FROM exam_result WHERE name = '孙悟空';

 4.1.2 删除整张表的数据

mysql> DELETE FROM exam_result;

 Delete 跟表名会删除所有数据,但是会自增长值会依然保留。

 4.2 truncate

  • 只能对整表操作,不能像 DELETE 一样针对部分数据操作;
  • 实际上 MySQL 不对数据操作,所以比 DELETE 更快,但是TRUNCATE在删除数据的时候,并不经过真正的事物,所以无法回滚。
  • 会重置 AUTO_INCREMENT 项
     

 5.插入查询结果

删除表中的重复记录,重复的数据只能有一份。

(1)先创建一个oldtable,向里面插入一些数据

mysql> select * from oldtable;
+------+------+
| id   | name |
+------+------+
|  100 | aaa  |
|  100 | aaa  |
|  200 | bbb  |
|  200 | bbb  |
|  300 | acb  |
|  300 | acb  |
+------+------+

(2)创建一个表,使用like语句以获得和目标对象一致的列属性

mysql> create table newtable like oldtable;
Query OK, 0 rows affected (0.01 sec)mysql> desc newtable;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+

(3)把oldtable里面的数据去重后插入

mysql> insert into newtable select distinct * from oldtable;
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0mysql> select * from newtable;
+------+------+
| id   | name |
+------+------+
|  100 | aaa  |
|  200 | bbb  |
|  300 | acb  |
+------+------+

(4) 将newtable重命名为oldtable

mysql> rename table oldtable to fordelete_table,newtable to oldtable;mysql> show tables;
+-----------------+
| Tables_in_test1 |
+-----------------+
| exam_result     |
| fordelete_table |
| myclass         |
| oldtable        |
| person          |

相关文章:

MySQL--表的基本查询--0410--15

目录 1. Create 1.1 insert 1.1.2 插入否则更新 1.2 replace 2.Retrieve 2.1 select 2.1.1 全列查询 2.1.2 指定列查询 2.1.3 查询字段为表达式 2.1.4 为查询结果指定名称 2.1.5 去重 2.2 where 2.2.1 > and > and < and < and 2.2.2 in between…...

Scala语言入门以及基本语法

文章目录 前言1.环境搭建1) IDEA中插件下载2) SDK下载配置 2.基本使用1&#xff09;var与val的区别2) .基本数据类型3).字符串的基本用法4) 控制结构1) if else2) for 循环3) while循环 5)类6) 函数 前言 scala在一种简洁的高级语言中结合了面向对象和函数式编程。Scala的静态…...

Linux shell编程 循环语句for continue break

for循环是编程语言中一种循环语句 示例1&#xff1a;循环读取user.txt中的用户名&#xff0c;创建用户。设置密码。 for i in $(cat /opt/user.txt) douseradd $iecho 123456 | passwd --stdin $i done 示例2&#xff1a;循环读取ipaddr文本文件中地址&#xff0c;执行ping命令…...

leetcode 643. 子数组最大平均数 I

题目描述解题思路执行结果 leetcode 643. 子数组最大平均数 I 题目描述 子数组最大平均数 I 给你一个由 n 个元素组成的整数数组 nums 和一个整数 k 。 请你找出平均数最大且 长度为 k 的连续子数组&#xff0c;并输出该最大平均数。 任何误差小于 10-5 的答案都将被视为正确答…...

TDA4VM/VH 芯片硬件 mailbox

请从官网下载 TD4VM 技术参考手册&#xff0c;地址如下&#xff1a; TDA4VM 技术参考手册地址 概述 (Mailbox 的介绍在 TRM 的第7.1章节) Mailbox 使用邮箱中断机制实现了 VM 芯片的核间通信。 Mailbox 是集成在 NAVSS0 域下的一个外设&#xff08;NAVSS0 的说明可以查看&a…...

如何利用Trimble RealWorks三维激光扫描仪进行外业测量和内业处理?

文章目录 0.引言1.Trimble RealWorks介绍2.外业测量3.内业处理 0.引言 笔者所在资源与环境工程学院实验室采购有一台Trimble RealWorks三维激光扫描仪&#xff08;仪器名&#xff1a;Trimble TX8&#xff09;&#xff0c;因项目需要&#xff0c;在学校实验场地进行实地测量训练…...

mysql数据备份

数据备份分类 数据库的备份类型 完全备份&#xff1a;对整个数据库的数据进行备份部分备份&#xff1a;对部分数据进行备份&#xff08;可以是一张表也可以是多张表&#xff09; 增量备份&#xff1a;是以上一次备份为基础来备份变更数据的&#xff0c;节约空间差异备份&#x…...

排队接水--贪心

排队接水 题目描述 有 n n n 个人在一个水龙头前排队接水&#xff0c;假如每个人接水的时间为 T i T_i Ti​&#xff0c;请编程找出这 n n n 个人排队的一种顺序&#xff0c;使得 n n n 个人的平均等待时间最小。 输入格式 第一行为一个整数 n n n。 第二行 n n n 个…...

数字温度传感器-DS18B20

文章目录 一、DS18B20器件图二、DS18B20特点三、DS18B20内部结构内部构成 四、工作时序1.初始化时序2.ReadOneChar2.WriteOneChar 一、DS18B20器件图 DS18B20的管脚排列&#xff1a; GND为电源地&#xff1b;DQ为数字信号输入&#xff0f;输出端&#xff1b;VDD为外接供电电源…...

【算法】【算法杂谈】从M个数中等概率的选出n个数,保证每一个数的选中概率都是n/m(蓄水池算法)

目录 前言问题介绍解决方案代码编写java语言版本c语言版本c语言版本 思考感悟写在最后 前言 当前所有算法都使用测试用例运行过&#xff0c;但是不保证100%的测试用例&#xff0c;如果存在问题务必联系批评指正~ 在此感谢左大神让我对算法有了新的感悟认识&#xff01; 问题介…...

vue3+ts+vite自适应项目——路由、layout布局

系列文章目录 第一章&#xff1a;搭建项目 目录 系列文章目录 前言 一、vue-router 1.安装vue-router 2.引入 2.1 新建页面 2.2 公共样式引入 2.3 layout 布局 2.4路由配置 总结 前言 上一章我们搭建了项目&#xff0c;这一张主要讲路由和layout布局&#xff0c;和…...

数据库之约束、索引和事务

一、约束 约束,顾名思义就是数据库对数据库中的数据所给出的一组检验规则.负责判断元素是否符合数据库要求.其目的就是为了提高效率以及准确性. 1.not null - > 数据元素非空 表示如果插入数据,则当前数据不能为空. //创建一张学生表,其班级id和年级id不为空 create …...

centos --libreoffice使用

您可以按照以下步骤在CentOS上安装LibreOffice&#xff1a; 打开终端并使用root用户登录。 运行以下命令更新系统软件包&#xff1a; yum update安装LibreOffice依赖项&#xff1a; yum install -y libreoffice-headless libreoffice-writer libreoffice-calc libreoffice-…...

Steam-V Rising 私人服务器架设教程

一、安装前的准备 一台服务器 拥有公网IP并且做好了端口映射 二、使用SteamCMD安装服务器 1.下载SteamCMD SteamCMD是Steam专用的命令行式客户端程序&#xff0c;所有的安装方式可以参照&#xff1a;https://developer.valvesoftware.com/wiki/SteamCMD 或者在其他站点自行…...

SpringBoot+Vue3实现登录验证码功能

系列文章目录 Redis缓存穿透、击穿、雪崩问题及解决方法Spring Cache的使用–快速上手篇分页查询–Java项目实战篇全局异常处理–Java实战项目篇 Java实现发送邮件&#xff08;定时自动发送邮件&#xff09;_java邮件通知_心态还需努力呀的博客-CSDN博客 该系列文章持续更新…...

spring2:创建和使用

目录 1.创建Spring项目 1.1创建Maven类 1.2添加Spring支持框架 1.3添加启动类 2.存储Bean对象 2.0 spring项目中添加配置文件(第一次) 2.1创建Bean 2.2把Bean注册到容器中 3.获取并使用Bean对象 3.1创建上下文 3.2获取指定Bean对象 getBean()方法 --> 获取什么…...

前端如何处理后端一次性传来的10w条数据?

写在前面 如果你在面试中被问到这个问题&#xff0c;你可以用下面的内容回答这个问题&#xff0c;如果你在工作中遇到这个问题&#xff0c;你应该先揍那个写 API 的人。 创建服务器 为了方便后续测试&#xff0c;我们可以使用node创建一个简单的服务器。 const http requir…...

Codeforces Round 867 (Div. 3)(A-G2)

文章目录 A. TubeTube Feed1、题目2、分析3、代码&#xff0c; B. Karina and Array1、题目2、分析3、代码 C. Bun Lover1、问题2、分析&#xff08;1&#xff09;观察样例法&#xff08;2&#xff09;正解推导 3、代码 D. Super-Permutation1、问题2、分析&#xff08;1&#…...

蓝奥声核心技术分享——一种无线低功耗配置技术

1.技术背景 无线低功耗配置技术指基于对目标场景状态变化的协同感知而获得触发响应并进行智能决策&#xff0c;属于蓝奥声核心技术--边缘协同感知(EICS&#xff09;技术的关键支撑性技术之一。该项技术涉及物联网边缘域的无线通信技术领域&#xff0c;具体主要涉及网络服务节点…...

kafka集群模拟单节点故障

这里通过kafka manage来展示节点宕机效果 现在三台主机节点均正常 topic正常识别到三个broker leader也均匀分配到了三个broker上 现在把节点id为0的主机模拟宕机 可以通过以上两张图片看到每个topic现在只识别到了两个broker节点,broker id为0的节点已经被剔除掉了 isr列…...

笔记:vue-cli-service

vue-cli-service serve 这个是什么意思&#xff1f; vue-cli-service serve 是一个 Vue.js CLI 命令&#xff0c;用于在本地开发环境下运行一个开发服务器&#xff0c;以便你可以在浏览器中查看和测试你的 Vue.js 应用程序。它在开发期间提供了自动重载、热模块替换和其它实用…...

Amazon S3 对象存储Java API操作记录(Minio与S3 SDK两种实现)

缘起 今年(2023年) 2月的时候做了个适配Amazon S3对象存储接口的需求&#xff0c;由于4月份自学考试临近&#xff0c;一直在备考就拖着没总结记录下&#xff0c;开发联调过程中也出现过一些奇葩的问题&#xff0c;最近人刚从考试缓过来顺手记录一下。 S3对象存储的基本概念 …...

ChatGPT技术原理 第六章:对话生成技术

目录 6.1 任务定义 6.2 基于检索的方法 6.3 基于生成的方法 6.4 评价指标 6.1 任务定义 对话生成技术是指使用自然语言处理技术生成与人类语言相似的对话。在对话生成任务中&#xff0c;模型需要理解输入的语境、用户的意图和上下文信息&#xff0c;然后生成能够回答用户问题…...

【C++ 八】写文件、读文件

写文件、读文件 文章目录 写文件、读文件前言1 文本文件1.1 写文件1.2 读文件 2 二进制文件2.1 写文件2.2 读文件 前言 本文包含文本文件写文件、文本文件读文件、二进制写文件、二进制读文件。 程序运行时产生的数据都属于临时数据&#xff0c;程序一旦运行结束都会被释放 通…...

【学习笔记】CF613E Puzzle Lover

这题本质上还是数据结构。 首先看到这个 2 n 2\times n 2n的网格图就很容易想到分治。我们还是考虑把要统计的东西变得可视化&#xff0c;一条路径要么穿过中线一次&#xff0c;那么我们可以将两边的串拼起来得到答案&#xff1b;要么穿过中线两次&#xff0c;考虑其中一边的…...

软考报名资格审核要多久?证明材料要哪些?

软考报名资格审核要多久&#xff1f; 一般来说&#xff0c;软考资格审核时间不超过1个工作日。当然&#xff0c;每个地区的具体情况都不一样。有些地区估计需要1-3个工作日。总之&#xff0c;为了顺利成功报名&#xff0c;大家应尽快报名&#xff0c;不要拖到最后一天。 软考…...

2023-04-27 polardbx-LSM-tree的Parallel Recovery性能优化

背景 数据库的Crash Recovery时长关系到数据库的可用性SLA、故障止损时间、升级效率等多个方面。本文描述了针对X-Engine数据库存储引擎的一种Crash Recovery优化手段,在典型场景下可以显著缩短数据库实例的故障恢复时间,提升用户使用感受。 当前面临的问题 X-Engine是阿里…...

创作纪念日让 AI 与我共同记录下今天 — 【第五周年、1460天】

今天正是五一&#xff0c;收到一条消息&#xff1f; 五一还要我加班 &#x1f60f;&#xff1f; 喔&#xff0c;原来是 CSDN 给我发的消息呀&#xff01;我在 CSDN 不知不觉已经开启第五周年啦&#xff01; 目录 1.机缘2.收获3.日常4.我与 AI 的“合作”part Ipart II Super al…...

枚举法计算24点游戏

# 请在此处编写代码 # 24点游戏 import itertools# 计算24点游戏代码 def twentyfour(cards):"""(1)itertools.permutations(可迭代对象)&#xff1a;通俗地讲&#xff0c;就是返回可迭代对象的所有数学全排列方式。itertools.permutations("1118") -…...

@Cacheable注解

Cacheable注解是Spring框架中提供的一种缓存技术&#xff0c; 用于标记一个方法的返回值可以被缓存起来&#xff0c;当再次调用该方法时&#xff0c;如果缓存中已经存在缓存的结果&#xff0c;则直接从缓存中获取结果而不是再次执行该方法&#xff0c;从而提高系统的性能和响应…...