基本查询【MySQL】

文章目录

  • 基本查询
  • 插入时是否更新
  • 替换
  • 查询
    • 指定列查询
    • 查询字段为表达式
    • 为查询结果指定别名
    • 结果去重
    • where条件
    • NULL 的查询
  • 结果排序
  • 筛选分页结果
  • Update
  • Delete
  • 截断表
  • 聚合函数
  • 分组(group by)
  • having && where

基本查询

建表

mysql> create table Student (-> id int unsigned primary key auto_increment,-> sn int unsigned unique key comment '学号',-> name varchar(20) not null ,-> qq varchar(20)  unique key -> );

指定列单行插入

mysql> insert into Student (sn,name,qq) values (123,'苏雪卿','4567890' ) ;
Query OK, 1 row affected (0.00 sec)
mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
+----+------+-----------+---------+
1 row in set (0.00 sec)

全列插入

mysql> insert into Student  values (10,222,'林游星','12346' ) ;
Query OK, 1 row affected (0.00 sec)mysql> 
mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
+----+------+-----------+---------+
2 rows in set (0.00 sec)

into可以省略

mysql> insert  Student  values (11,333,'林斩令','1254546' ) ;
Query OK, 1 row affected (0.00 sec)
mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
+----+------+-----------+---------+
3 rows in set (0.00 sec)

多行插入

mysql> insert into Student values (12,127,'曹操','3515545') ,(14,128,'许褚','545445') ;
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
+----+------+-----------+---------+
5 rows in set (0.00 sec)
mysql> insert into Student (sn,name,qq) values (5151,'诸葛亮','35155') ,(545,'单沙禹','545') ;
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
| 15 | 5151 | 诸葛亮    | 35155   |
| 16 |  545 | 单沙禹    | 545     |
+----+------+-----------+---------+
7 rows in set (0.00 sec)

插入时是否更新

如果发生键值冲突 ,需要修改数据

mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
| 15 | 5151 | 诸葛亮    | 35155   |
| 16 |  545 | 单沙禹    | 545     |
+----+------+-----------+---------+
7 rows in set (0.00 sec)mysql> insert into Student  values (15,20,'xuchu','8888') on duplicate key update sn=20,name='xuchu',qq=''8888';
Query OK, 2 rows affected (0.00 sec)mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
| 15 |   20 | xuchu     | 8888    |
| 16 |  545 | 单沙禹    | 545     |
+----+------+-----------+---------+
7 rows in set (0.00 sec)

在这里插入图片描述

有冲突:Query OK, 2 rows affected (0.00 sec)

没有冲突:Query OK, 1 rows affected (0.00 sec)

要更新的数据和之前的数据一样,就不更新了:Query OK, 0 rows affected (0.00 sec)

mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
| 15 |   20 | xuchu     | 8888    |
| 16 |  545 | 单沙禹    | 545     |
+----+------+-----------+---------+
7 rows in set (0.00 sec)mysql> insert into Student  values (17,22,'雪如之','888') on duplicate key update sn=22,name='雪如之',qq=='888';
Query OK, 1 row affected (0.01 sec)mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
| 15 |   20 | xuchu     | 8888    |
| 16 |  545 | 单沙禹    | 545     |
| 17 |   22 | 雪如之    | 888     |
+----+------+-----------+---------+
8 rows in set (0.00 sec)
mysql> insert into Student  values (17,22,'雪如之','888') on duplicate key update sn=22,name='雪如之',qq='888';
Query OK, 0 rows affected (0.00 sec)

替换

1 row affected ,表中没有冲突数据,数据被插入

主键或者唯一键没有冲突,则直接插入

mysql> replace into Student (sn,name,qq) values (140,'许攸', '2222') ;
Query OK, 1 row affected (0.00 sec)mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
| 15 |   20 | xuchu     | 8888    |
| 16 |  545 | 单沙禹    | 545     |
| 17 |   22 | 雪如之    | 888     |
| 18 |  140 | 许攸      | 2222    |
+----+------+-----------+---------+
9 rows in set (0.00 sec)

2 rows affected ,表中有冲突数据,删除后重新插入

主键或者唯一键如果冲突,则删除后再插入

mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
| 15 |   20 | xuchu     | 8888    |
| 16 |  545 | 单沙禹    | 545     |
| 17 |   22 | 雪如之    | 888     |
| 18 |  140 | 许攸      | 2222    |
+----+------+-----------+---------+
9 rows in set (0.00 sec)mysql> replace into Student (sn,name,qq) values (140,'许攸1', '2222') ;
Query OK, 2 rows affected (0.00 sec)mysql> select * from Student;
+----+------+-----------+---------+
| id | sn   | name      | qq      |
+----+------+-----------+---------+
|  1 |  123 | 苏雪卿    | 4567890 |
| 10 |  222 | 林游星    | 12346   |
| 11 |  333 | 林斩令    | 1254546 |
| 12 |  127 | 曹操      | 3515545 |
| 14 |  128 | 许褚      | 545445  |
| 15 |   20 | xuchu     | 8888    |
| 16 |  545 | 单沙禹    | 545     |
| 17 |   22 | 雪如之    | 888     |
| 19 |  140 | 许攸1     | 2222    |
+----+------+-----------+---------+
9 rows in set (0.00 sec)

查询

全列查询

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);
Query OK, 7 rows affected (0.00 sec)
Records: 7  Duplicates: 0  Warnings: 0mysql> 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 |
+----+-----------+---------+------+---------+
7 rows in set (0.00 sec)

指定列查询

mysql> select id from  exam_result ;
+----+
| id |
+----+
|  1 |
|  2 |
|  3 |
|  4 |
|  5 |
|  6 |
|  7 |
+----+
7 rows in set (0.00 sec)mysql> select id ,math from  exam_result ;
+----+------+
| id | math |
+----+------+
|  1 |   98 |
|  2 |   78 |
|  3 |   98 |
|  4 |   84 |
|  5 |   85 |
|  6 |   73 |
|  7 |   65 |
+----+------+
7 rows in set (0.00 sec)

查询字段为表达式

mysql> select name,math ,math+chinese+english  from  exam_result ;
+-----------+------+----------------------+
| name      | math | math+chinese+english |
+-----------+------+----------------------+
| 唐三藏    |   98 |                  221 |
| 孙悟空    |   78 |                  242 |
| 猪悟能    |   98 |                  276 |
| 曹孟德    |   84 |                  233 |
| 刘玄德    |   85 |                  185 |
| 孙权      |   73 |                  221 |
| 宋公明    |   65 |                  170 |
+-----------+------+----------------------+
7 rows in set (0.00 sec)

为查询结果指定别名

mysql> select name,math ,math+chinese+english as total  from  exam_result ;
+-----------+------+-------+
| name      | math | total |
+-----------+------+-------+
| 唐三藏    |   98 |   221 |
| 孙悟空    |   78 |   242 |
| 猪悟能    |   98 |   276 |
| 曹孟德    |   84 |   233 |
| 刘玄德    |   85 |   185 |
| 孙权      |   73 |   221 |
| 宋公明    |   65 |   170 |
+-----------+------+-------+
7 rows in set (0.00 sec)

在这里插入图片描述

as可以省略

mysql> select name 姓名,math 数学 ,math+chinese+english  总分  from  exam_result ;
+-----------+--------+--------+
| 姓名      | 数学   | 总分   |
+-----------+--------+--------+
| 唐三藏    |     98 |    221 |
| 孙悟空    |     78 |    242 |
| 猪悟能    |     98 |    276 |
| 曹孟德    |     84 |    233 |
| 刘玄德    |     85 |    185 |
| 孙权      |     73 |    221 |
| 宋公明    |     65 |    170 |
+-----------+--------+--------+
7 rows in set (0.00 sec)
mysql> select name 姓名,math 数学 ,math+10  from  exam_result ;
+-----------+--------+---------+
| 姓名      | 数学   | math+10 |
+-----------+--------+---------+
| 唐三藏    |     98 |     108 |
| 孙悟空    |     78 |      88 |
| 猪悟能    |     98 |     108 |
| 曹孟德    |     84 |      94 |
| 刘玄德    |     85 |      95 |
| 孙权      |     73 |      83 |
| 宋公明    |     65 |      75 |
+-----------+--------+---------+
7 rows in set (0.00 sec)

结果去重

mysql> select distinct math from exam_result ;
+------+
| math |
+------+
|   98 |
|   78 |
|   84 |
|   85 |
|   73 |
|   65 |
+------+
6 rows in set (0.00 sec)

where条件

比较运算符:

在这里插入图片描述

逻辑运算符:

在这里插入图片描述

mysql> select  name ,english from exam_result  where english<60 ;
+-----------+---------+
| name      | english |
+-----------+---------+
| 唐三藏    |      56 |
| 刘玄德    |      45 |
| 宋公明    |      30 |
+-----------+---------+
3 rows in set (0.00 sec)
mysql> select name, chinese from exam_result where chinese>=80 and chinese<=90;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 孙悟空    |      87 |
| 猪悟能    |      88 |
| 曹孟德    |      82 |
+-----------+---------+
3 rows in set (0.00 sec)

select name, chinese from exam_result where chinese>=80 and chinese<=90;

select name, chinese from exam_result where chinese between 80 and 90;

这两行SQL是一样的

mysql> select name, chinese from exam_result where math=58 or math=59 or math=98 or math=99;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 唐三藏    |      67 |
| 猪悟能    |      88 |
+-----------+---------+
2 rows in set (0.00 sec)mysql> select name, chinese from exam_result where math in (58,59,98,99);
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 唐三藏    |      67 |
| 猪悟能    |      88 |
+-----------+---------+
2 rows in set (0.00 sec)

select name, chinese from exam_result where math=58 or math=59 or math=98 or math=99;

select name, chinese from exam_result where math in (58,59,98,99);

这两行SQL是一样的

% 匹配任意多个(包括 0 个)任意字符

例如:姓孙

mysql> select name, chinese from exam_result where name like '孙%';
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 孙悟空    |      87 |
| 孙权      |      70 |
+-----------+---------+
2 rows in set (0.00 sec)

_ 匹配严格的一个任意字符

例如:孙某

mysql> select name, chinese from exam_result where name like '孙_';
+--------+---------+
| name   | chinese |
+--------+---------+
| 孙权   |      70 |
+--------+---------+
1 row in set (0.00 sec)

查询英语成绩比语文成绩好的同学

mysql> select name, chinese ,english from exam_result where  chinese >english;
+-----------+---------+---------+
| name      | chinese | english |
+-----------+---------+---------+
| 唐三藏    |      67 |      56 |
| 孙悟空    |      87 |      77 |
| 曹孟德    |      82 |      67 |
| 刘玄德    |      55 |      45 |
| 宋公明    |      75 |      30 |
+-----------+---------+---------+
5 rows in set (0.00 sec)
mysql> select name ,chinese+english+math total from exam result where total <200 ;
ERROR 1146 (42S02): Table 'test_db.exam' doesn't exist

上述写法是错误的

SQL语句执行顺序:

在这里插入图片描述

例如:查询英语成绩+语文成绩+数学成绩 <200的同学

mysql> select name ,chinese+english+math as  total from exam_result where chinese+english+math  <200 ;
+-----------+-------+
| name      | total |
+-----------+-------+
| 刘玄德    |   185 |
| 宋公明    |   170 |
+-----------+-------+
2 rows in set (0.00 sec)

语文成绩 > 80 并且不姓孙的同学

mysql> select name ,chinese from exam_result where chinese>80 and name  not like '孙%' ;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 猪悟能    |      88 |
| 曹孟德    |      82 |
+-----------+---------+
2 rows in set (0.00 sec)

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

mysql> select   name, chinese, math, english, chinese + math + english  总分 from exam_result where name like '孙_' or     (   chinese + math + english > 200 and chinese < math and english > 80        )  ;
+-----------+---------+------+---------+--------+
| name      | chinese | math | english | 总分   |
+-----------+---------+------+---------+--------+
| 猪悟能    |      88 |   98 |      90 |    276 |
| 孙权      |      70 |   73 |      78 |    221 |
+-----------+---------+------+---------+--------+
2 rows in set (0.00 sec)

NULL 的查询

mysql> create table test(-> id int ,-> name varchar(20) -> );
Query OK, 0 rows affected (0.01 sec)mysql> insert into test (id ,name) values(1,'张三') ;
Query OK, 1 row affected (0.00 sec)mysql> insert into test (id ,name) values(null,'张三') ;
Query OK, 1 row affected (0.00 sec)mysql> insert into test (id ,name) values(1,null) ;
Query OK, 1 row affected (0.00 sec)mysql> insert into test (id ,name) values(null,null) ;
Query OK, 1 row affected (0.00 sec)mysql> insert into test (id ,name) values(1,'') ;
Query OK, 1 row affected (0.00 sec)mysql> select * from test ;
+------+--------+
| id   | name   |
+------+--------+
|    1 | 张三   |
| NULL | 张三   |
|    1 | NULL   |
| NULL | NULL   |
|    1 |        |
+------+--------+
5 rows in set (0.00 sec)

查询表中name为null

mysql> select  * from test where name is null ;
+------+------+
| id   | name |
+------+------+
|    1 | NULL |
| NULL | NULL |
+------+------+
2 rows in set (0.00 sec)

查询表中name为空串

mysql> select  * from test where name ='' ;
+------+------+
| id   | name |
+------+------+
|    1 |      |
+------+------+
1 row in set (0.00 sec)

查询表中name不为空

mysql> select  * from test where name is not null;
+------+--------+
| id   | name   |
+------+--------+
|    1 | 张三   |
| NULL | 张三   |
|    1 |        |
+------+--------+
3 rows in set (0.00 sec)

在这里插入图片描述

结果排序

desc,降序

asc,升序

mysql> select name ,math from exam_result  order by math desc ;
+-----------+------+
| name      | math |
+-----------+------+
| 唐三藏    |   98 |
| 猪悟能    |   98 |
| 刘玄德    |   85 |
| 曹孟德    |   84 |
| 孙悟空    |   78 |
| 孙权      |   73 |
| 宋公明    |   65 |
+-----------+------+
7 rows in set (0.00 sec)mysql> select name ,math from exam_result  order by math asc ;
+-----------+------+
| name      | math |
+-----------+------+
| 宋公明    |   65 |
| 孙权      |   73 |
| 孙悟空    |   78 |
| 曹孟德    |   84 |
| 刘玄德    |   85 |
| 唐三藏    |   98 |
| 猪悟能    |   98 |
+-----------+------+
7 rows in set (0.00 sec)

NULL值比任何值都要小

mysql> select name from test order by name desc ;
+--------+
| name   |
+--------+
| 张三   |
| 张三   |
|        |
| NULL   |
| NULL   |
+--------+
5 rows in set (0.00 sec)mysql> select name from test order by name asc;
+--------+
| name   |
+--------+
| NULL   |
| NULL   |
|        |
| 张三   |
| 张三   |
+--------+
5 rows in set (0.00 sec)

查询同学各门成绩,依次按 数学降序,英语降序,语文升序的方式

mysql> select name, math , english ,chinese from exam_result   order by math desc , english desc ,chinese asc ;
+-----------+------+---------+---------+
| name      | math | english | chinese |
+-----------+------+---------+---------+
| 猪悟能    |   98 |      90 |      88 |
| 唐三藏    |   98 |      56 |      67 |
| 刘玄德    |   85 |      45 |      55 |
| 曹孟德    |   84 |      67 |      82 |
| 孙悟空    |   78 |      77 |      87 |
| 孙权      |   73 |      78 |      70 |
| 宋公明    |   65 |      30 |      75 |
+-----------+------+---------+---------+
7 rows in set (0.00 sec)

order by 默认升序

查询同学及总分,由高到低

mysql> select name, math+chinese+english as total  from exam_result   order by total desc;
+-----------+-------+
| name      | total |
+-----------+-------+
| 猪悟能    |   276 |
| 孙悟空    |   242 |
| 曹孟德    |   233 |
| 唐三藏    |   221 |
| 孙权      |   221 |
| 刘玄德    |   185 |
| 宋公明    |   170 |
+-----------+-------+
7 rows in set (0.00 sec)

在这里插入图片描述

需要有数据才排序

查询姓孙的同学或者姓曹的同学数学成绩,结果按数学成绩由高到低显示

mysql> select name, math   from exam_result  where name like '孙%' or name like '曹%'  order by math  des
sc;
+-----------+------+
| name      | math |
+-----------+------+
| 曹孟德    |   84 |
| 孙悟空    |   78 |
| 孙权      |   73 |
+-----------+------+
3 rows in set (0.00 sec)

筛选分页结果

mysql> select  * from  exam_result  limit 3 ;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
|  2 | 孙悟空    |      87 |   78 |      77 |
|  3 | 猪悟能    |      88 |   98 |      90 |
+----+-----------+---------+------+---------+
3 rows in set (0.00 sec)mysql> select  * from  exam_result  limit 2,4;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      82 |   84 |      67 |
|  5 | 刘玄德    |      55 |   85 |      45 |
|  6 | 孙权      |      70 |   73 |      78 |
+----+-----------+---------+------+---------+
4 rows in set (0.00 sec)

在这里插入图片描述

mysql> select  * from  exam_result  limit 3 offset 0;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
|  2 | 孙悟空    |      87 |   78 |      77 |
|  3 | 猪悟能    |      88 |   98 |      90 |
+----+-----------+---------+------+---------+
3 rows in set (0.00 sec)

在这里插入图片描述

Update

将孙悟空同学的数学成绩变更为 80

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 |
+----+-----------+---------+------+---------+
7 rows in set (0.00 sec)mysql> update   exam_result  set math=80  where  name='孙悟空' ;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> select * from exam_result ;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
|  2 | 孙悟空    |      87 |   80 |      77 |
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      82 |   84 |      67 |
|  5 | 刘玄德    |      55 |   85 |      45 |
|  6 | 孙权      |      70 |   73 |      78 |
|  7 | 宋公明    |      75 |   65 |      30 |
+----+-----------+---------+------+---------+
7 rows in set (0.01 sec)

将曹孟德同学的数学成绩变更为 60 分,语文成绩变更为 70 分

mysql> update   exam_result  set math=60 ,chinese=70  where  name='曹孟德' ;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> select * from exam_result ;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
|  2 | 孙悟空    |      87 |   80 |      77 |
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      70 |   60 |      67 |
|  5 | 刘玄德    |      55 |   85 |      45 |
|  6 | 孙权      |      70 |   73 |      78 |
|  7 | 宋公明    |      75 |   65 |      30 |
+----+-----------+---------+------+---------+
7 rows in set (0.00 sec)

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

mysql> select name , math+chinese+english as total   from exam_result  order by  total asc limit 3 ;
+-----------+-------+
| name      | total |
+-----------+-------+
| 宋公明    |   170 |
| 刘玄德    |   185 |
| 曹孟德    |   197 |
+-----------+-------+
3 rows in set (0.00 sec)mysql> update exam_result  set math=math+30 order by math+chinese+english asc limit 3 ;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0mysql> select name,  math+chinese+english   total  from exam_result order by total limit 3 ;
Display all 909 possibilities? (y or n) 
mysql> select name,  math+chinese+english   total  from exam_result order by total  asc  limit 3 ;
+-----------+-------+
| name      | total |
+-----------+-------+
| 宋公明    |   200 |
| 刘玄德    |   215 |
| 唐三藏    |   221 |
+-----------+-------+
3 rows in set (0.00 sec)mysql> select name , math+chinese+english  from  exam_result  order  by  math+chinese+english asc ;
+-----------+----------------------+
| name      | math+chinese+english |
+-----------+----------------------+
| 宋公明    |                  200 |
| 刘玄德    |                  215 |
| 唐三藏    |                  221 |
| 孙权      |                  221 |
| 曹孟德    |                  227 |
| 孙悟空    |                  244 |
| 猪悟能    |                  276 |
+-----------+----------------------+
7 rows in set (0.00 sec)

Delete

删除孙悟空同学的考试成绩

mysql> select  * from exam_result  where name='孙悟空'; 
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  2 | 孙悟空    |      87 |   80 |      77 |
+----+-----------+---------+------+---------+
1 row in set (0.00 sec)mysql> delete  from exam_result  where name='孙悟空';
Query OK, 1 row affected (0.01 sec)

找到倒数第一同学的考试成绩,并删除

mysql> select name , math+chinese+english  as total from  exam_result order by   total  asc limit 1;
+-----------+-------+
| name      | total |
+-----------+-------+
| 宋公明    |   200 |
+-----------+-------+
1 row in set (0.00 sec)mysql> delete   from exam_result    order by math+chinese+english  asc limit 1 ;
Query OK, 1 row affected (0.00 sec)mysql> select name , math+chinese+english  as total from  exam_result order by   total  asc limit 1;
+-----------+-------+
| name      | total |
+-----------+-------+
| 刘玄德    |   215 |
+-----------+-------+
1 row in set (0.00 sec)
mysql> CREATE TABLE for_delete (-> id INT PRIMARY KEY AUTO_INCREMENT,-> name VARCHAR(20)-> );
Query OK, 0 rows affected (0.01 sec)mysql> INSERT INTO for_delete (name) VALUES ('A'), ('B'), ('C');
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0mysql> show create table for_delete  \G ;
*************************** 1. row ***************************Table: for_delete
Create Table: CREATE TABLE `for_delete` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(20) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)mysql>  show create table for_delete  \G ;
*************************** 1. row ***************************Table: for_delete
Create Table: CREATE TABLE `for_delete` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(20) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)mysql> select * from for_delete ;
Empty set (0.00 sec)

在这里插入图片描述

删除表后,自增还是4

截断表

TRUNCATE

只能对整表操作,不能像 DELETE 一样针对部分数据操作;

实际上 MySQL 不对数据操作,所以比 DELETE 更快,但是TRUNCATE在删除数据的时候,并不经过真正的事
物,所以无法回滚

会重置 AUTO_INCREMENT 项

mysql> CREATE TABLE for_truncate (-> id INT PRIMARY KEY AUTO_INCREMENT,-> name VARCHAR(20)-> );
Query OK, 0 rows affected (0.02 sec)mysql> INSERT INTO for_truncate (name) VALUES ('A'), ('B'), ('C'); 
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0mysql> show create table for_truncate \G
*************************** 1. row ***************************Table: for_truncate
Create Table: CREATE TABLE `for_truncate` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(20) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)mysql> truncate for_truncate ;
Query OK, 0 rows affected (0.14 sec)mysql> select * from for_truncate ;
Empty set (0.00 sec)mysql> show create table for_truncate \G
*************************** 1. row ***************************Table: for_truncate
Create Table: CREATE TABLE `for_truncate` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(20) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

在这里插入图片描述

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

mysql> select * from  duplicate_table ;
+------+------+
| id   | name |
+------+------+
|  100 | aaa  |
|  100 | aaa  |
|  200 | bbb  |
|  200 | bbb  |
|  200 | bbb  |
|  300 | ccc  |
+------+------+
6 rows in set (0.00 sec)mysql> select distinct * from duplicate_table ;
+------+------+
| id   | name |
+------+------+
|  100 | aaa  |
|  200 | bbb  |
|  300 | ccc  |
+------+------+
3 rows in set (0.00 sec)--创建一张空表 no_duplicate_table,结构和 duplicate_table 一样
mysql> create table no_duplicate_table like duplicate_table;
Query OK,0 rows affected (0.04 sec)-- 将 duplicate_table 的去重数据插入到 no_duplicate_table
mysql> insert into no_duplicate_table select distinct * from duplicate_table ;
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0mysql> select * from  no_duplicate_table ; 
+------+------+
| id   | name |
+------+------+
|  100 | aaa  |
|  200 | bbb  |
|  300 | ccc  |
+------+------+
3 rows in set (0.00 sec)
-- 重命名表
mysql> RENAME TABLE duplicate_table TO old_duplicate_table,-> no_duplicate_table TO duplicate_table;
Query OK, 0 rows affected (0.01 sec)mysql> SELECT * FROM duplicate_table; 
+------+------+
| id   | name |
+------+------+
|  100 | aaa  |
|  200 | bbb  |
|  300 | ccc  |
+------+------+
3 rows in set (0.00 sec)

聚合函数

COUNT([DISTINCT] expr) 返回查询到的数据的 数量
SUM([DISTINCT] expr) 返回查询到的数据的 总和,不是数字没有意义
AVG([DISTINCT] expr) 返回查询到的数据的 平均值,不是数字没有意义
MAX([DISTINCT] expr) 返回查询到的数据的 最大值,不是数字没有意义
MIN([DISTINCT] expr) 返回查询到的数据的 最小值,不是数字没有意义

mysql> select * from exam_result;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      70 |   90 |      67 |
|  5 | 刘玄德    |      55 |  115 |      45 |
|  6 | 孙权      |      70 |   73 |      78 |
+----+-----------+---------+------+---------+
5 rows in set (0.00 sec)mysql> select count(*) from  exam_result ;
+----------+
| count(*) |
+----------+
|        5 |
+----------+
1 row in set (0.00 sec)mysql> select count(*) 总数  from  exam_result ;
+--------+
| 总数   |
+--------+
|      5 |
+--------+
1 row in set (0.00 sec)
mysql> select count(1) 总数  from  exam_result ;
+--------+
| 总数   |
+--------+
|      5 |
+--------+
1 row in set (0.00 sec)mysql> select count(2) 总数  from  exam_result ;
+--------+
| 总数   |
+--------+
|      5 |
+--------+
1 row in set (0.01 sec)
mysql> select count(math) from    exam_result   ;
+-------------+
| count(math) |
+-------------+
|           5 |
+-------------+
1 row in set (0.00 sec)

统计本次考试,不重复的数学成绩分数个数

mysql> select  count(distinct math) as res from exam_result ;
+-----+
| res |
+-----+
|   4 |
+-----+
1 row in set (0.00 sec)

统计数学成绩总分

mysql> select sum(math) from exam_result ;
+-----------+
| sum(math) |
+-----------+
|       474 |
+-----------+
1 row in set (0.01 sec)

统计平均分

mysql> select sum(math)/count(*) from exam_result ;
+--------------------+
| sum(math)/count(*) |
+--------------------+
|               94.8 |
+--------------------+
1 row in set (0.00 sec)mysql> select avg(math) from exam_result ;
+-----------+
| avg(math) |
+-----------+
|      94.8 |
+-----------+
1 row in set (0.00 sec)

返回英语最高分

mysql> select max(english) from  exam_result ;
+--------------+
| max(english) |
+--------------+
|           90 |
+--------------+
1 row in set (0.00 sec)

返回 > 70 分以上的数学最低分

mysql>  select min(math) from  exam_result  where math>70 ;
+-----------+
| min(math) |
+-----------+
|        73 |
+-----------+
1 row in set (0.00 sec)

分组(group by)

分组的目的是为了进行分组之后,方便进行聚合统计

显示每个部门的平均工资和最高工资

mysql> select * from emp;
+--------+--------+-----------+------+---------------------+---------+---------+--------+
| empno  | ename  | job       | mgr  | hiredate            | sal     | comm    | deptno |
+--------+--------+-----------+------+---------------------+---------+---------+--------+
| 007369 | SMITH  | CLERK     | 7902 | 1980-12-17 00:00:00 |  800.00 |    NULL |     20 |
| 007499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 00:00:00 | 1600.00 |  300.00 |     30 |
| 007521 | WARD   | SALESMAN  | 7698 | 1981-02-22 00:00:00 | 1250.00 |  500.00 |     30 |
| 007566 | JONES  | MANAGER   | 7839 | 1981-04-02 00:00:00 | 2975.00 |    NULL |     20 |
| 007654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 00:00:00 | 1250.00 | 1400.00 |     30 |
| 007698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 00:00:00 | 2850.00 |    NULL |     30 |
| 007782 | CLARK  | MANAGER   | 7839 | 1981-06-09 00:00:00 | 2450.00 |    NULL |     10 |
| 007788 | SCOTT  | ANALYST   | 7566 | 1987-04-19 00:00:00 | 3000.00 |    NULL |     20 |
| 007839 | KING   | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 |    NULL |     10 |
| 007844 | TURNER | SALESMAN  | 7698 | 1981-09-08 00:00:00 | 1500.00 |    0.00 |     30 |
| 007876 | ADAMS  | CLERK     | 7788 | 1987-05-23 00:00:00 | 1100.00 |    NULL |     20 |
| 007900 | JAMES  | CLERK     | 7698 | 1981-12-03 00:00:00 |  950.00 |    NULL |     30 |
| 007902 | FORD   | ANALYST   | 7566 | 1981-12-03 00:00:00 | 3000.00 |    NULL |     20 |
| 007934 | MILLER | CLERK     | 7782 | 1982-01-23 00:00:00 | 1300.00 |    NULL |     10 |
+--------+--------+-----------+------+---------------------+---------+---------+--------+
14 rows in set (0.00 sec)mysql> select  deptno, max(sal) 最高, avg(sal)  平均 from emp group by deptno ;
+--------+---------+-------------+
| deptno | 最高    | 平均        |
+--------+---------+-------------+
|     10 | 5000.00 | 2916.666667 |
|     20 | 3000.00 | 2175.000000 |
|     30 | 2850.00 | 1566.666667 |
+--------+---------+-------------+
3 rows in set (0.00 sec)

显示每个部门的每种岗位的平均工资和最低工资

mysql> select  deptno,job   ,avg(sal)  平均, min(sal) 最低  from emp group by deptno,job ;
+--------+-----------+-------------+---------+
| deptno | job       | 平均        | 最低    |
+--------+-----------+-------------+---------+
|     10 | CLERK     | 1300.000000 | 1300.00 |
|     10 | MANAGER   | 2450.000000 | 2450.00 |
|     10 | PRESIDENT | 5000.000000 | 5000.00 |
|     20 | ANALYST   | 3000.000000 | 3000.00 |
|     20 | CLERK     |  950.000000 |  800.00 |
|     20 | MANAGER   | 2975.000000 | 2975.00 |
|     30 | CLERK     |  950.000000 |  950.00 |
|     30 | MANAGER   | 2850.000000 | 2850.00 |
|     30 | SALESMAN  | 1400.000000 | 1250.00 |
+--------+-----------+-------------+---------+
9 rows in set (0.00 sec)

在这里插入图片描述

指定列名,实际分组,是用该列的不同的行数据来进行分组的

分组的条件deptno,组内一定是相同的 ,相同就意味着可以被聚合压缩

分组,就是把一组按照特定条件拆成了多个组,进行各自组内的统计

将分组理解为分表,就是把一张表按照特定条件在逻辑上拆成了多个子表,然后分别对各自的子表进行聚合统计

显示平均工资低于2000的部门和它的平均工资

ysql> select   deptno , avg(sal)   deptavg from emp group by deptno   having deptavg  < 2000 ;
+--------+-------------+
| deptno | deptavg     |
+--------+-------------+
|     30 | 1566.666667 |
+--------+-------------+
1 row in set (0.00 sec)

在这里插入图片描述

having是对聚合后的统计数据,条件筛选

having && where

having 和where 都能条件筛选

mysql> select * from emp ;
+--------+--------+-----------+------+---------------------+---------+---------+--------+
| empno  | ename  | job       | mgr  | hiredate            | sal     | comm    | deptno |
+--------+--------+-----------+------+---------------------+---------+---------+--------+
| 007369 | SMITH  | CLERK     | 7902 | 1980-12-17 00:00:00 |  800.00 |    NULL |     20 |
| 007499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 00:00:00 | 1600.00 |  300.00 |     30 |
| 007521 | WARD   | SALESMAN  | 7698 | 1981-02-22 00:00:00 | 1250.00 |  500.00 |     30 |
| 007566 | JONES  | MANAGER   | 7839 | 1981-04-02 00:00:00 | 2975.00 |    NULL |     20 |
| 007654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 00:00:00 | 1250.00 | 1400.00 |     30 |
| 007698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 00:00:00 | 2850.00 |    NULL |     30 |
| 007782 | CLARK  | MANAGER   | 7839 | 1981-06-09 00:00:00 | 2450.00 |    NULL |     10 |
| 007788 | SCOTT  | ANALYST   | 7566 | 1987-04-19 00:00:00 | 3000.00 |    NULL |     20 |
| 007839 | KING   | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 |    NULL |     10 |
| 007844 | TURNER | SALESMAN  | 7698 | 1981-09-08 00:00:00 | 1500.00 |    0.00 |     30 |
| 007876 | ADAMS  | CLERK     | 7788 | 1987-05-23 00:00:00 | 1100.00 |    NULL |     20 |
| 007900 | JAMES  | CLERK     | 7698 | 1981-12-03 00:00:00 |  950.00 |    NULL |     30 |
| 007902 | FORD   | ANALYST   | 7566 | 1981-12-03 00:00:00 | 3000.00 |    NULL |     20 |
| 007934 | MILLER | CLERK     | 7782 | 1982-01-23 00:00:00 | 1300.00 |    NULL |     10 |
+--------+--------+-----------+------+---------------------+---------+---------+--------+
14 rows in set (0.00 sec)mysql> select  deptno,job,avg(sal) myavg from emp where ename !='SMITH' group by deptno , job having myavg<2000 ;
+--------+----------+-------------+
| deptno | job      | myavg       |
+--------+----------+-------------+
|     10 | CLERK    | 1300.000000 |
|     20 | CLERK    | 1100.000000 |
|     30 | CLERK    |  950.000000 |
|     30 | SALESMAN | 1400.000000 |
+--------+----------+-------------+
4 rows in set (0.00 sec)

在这里插入图片描述

having和 where , 条件筛选的阶段是不同的

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/462787.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android15音频进阶之Cuttlefish搭建音频开发环境(九十二)

简介: CSDN博客专家、《Android系统多媒体进阶实战》一书作者 新书发布:《Android系统多媒体进阶实战》🚀 优质专栏: Audio工程师进阶系列【原创干货持续更新中……】🚀 优质专栏: 多媒体系统工程师系列【原创干货持续更新中……】🚀 优质视频课程:AAOS车载系统+…

Qt QCheckBox、QPushButton和QRadioButton详解

QCheckBox&#xff08;复选框&#xff09; 功能&#xff1a;QCheckBox用于创建一个复选框控件&#xff0c;允许用户从多个选项中选择多个。 属性&#xff1a; checkable&#xff1a;决定复选框是否可以被选中或取消选中。checked&#xff1a;表示复选框当前的选中状态&#…

【SpringMVC】传递json,获取url参数,上传文件

【传递json数据】 【json概念】 一种轻量级数据交互格式&#xff0c;有自己的格式和语法&#xff0c;使用文本表示一个对象或数组的信息&#xff0c;其本质上是字符串&#xff0c;负责在不同的语言中数据传递与交换 json数据以字符串的形式体现 【json字符串与Java对象互转…

2024/11/1 操作系统pv大题总结

2014&#xff1a; 2022&#xff1a; 2020&#xff1a; 2019&#xff1a; 2011&#xff1a; 读者写者问题&#xff1a;

00-开发环境 MPLAB IDE 配置

MPLAB IDE V8.83 File 菜单简介 New (CtrlN)&#xff1a; 创建一个新文件&#xff0c;用于编写新的代码。 Add New File to Project...&#xff1a; 将新文件添加到当前项目中。 Open... (CtrlO)&#xff1a; 打开现有文件。 Close (CtrlE)&#xff1a; 关闭当前打开的文件。 …

如何在Apple Vision Pro上打造成功的沉浸式叙述应用

随着科技的进步,沉浸式叙述应用正在成为一种全新的娱乐方式。Apple Vision Pro的发布,标志着空间计算技术迈上了新的台阶。本文将探讨如何在Vision Pro上构建一款类似Encounter Dinosaur的沉浸式叙述应用,具体通过分析《Out There》这款作品,总结出一系列关键点,帮助创作者…

Linux练习作业

1.搭建dns服务器能够对自定义的正向或者反向域完成数据解析查询。 2.配置从DNS服务器&#xff0c;对主dns服务器进行数据备份 环境准备 主从服务器都需要进行的操作#关闭防火墙、SELinnux systemctl stop firewalld setenforce 0#软件安装 yum install bind -y实验一&#…

计算机网络:网络层 —— IP 多播技术

文章目录 基本概念IP多播地址和多播组 IP多播的类型硬件多播将IPv4多播地址映射为多播MAC地址 基本概念 多播&#xff08;Multicast&#xff0c;也称为组播&#xff09;是一种实现“一对多”通信的技术&#xff0c;允许一台或多台主机&#xff08;多播源&#xff09;发送单一数…

掌握AI Prompt的艺术:如何有效引导智能助手

开头叙述&#xff1a; 在人工智能的世界里&#xff0c;Prompt&#xff08;提示&#xff09;是沟通人类意图与机器理解之间的桥梁。它不仅是一串简单的文字&#xff0c;而是一把钥匙&#xff0c;能够解锁AI模型的潜力&#xff0c;引导它们执行复杂的任务。本文将探讨Prompt的重…

[SAP ABAP] SMW0上传模板

通常来说&#xff0c;一个批量导入的程序必须使用指定的模板&#xff0c;我们需要将模板保存到SAP系统中&#xff0c;以便用户下载并更改。这里我们可以使用事务码SMW0解决上述的问题 1.选择二进制类型 2.输入存放的包 3.创建对象 选择需要进行上传的本地模板文件到SAP系统中 …

第二十六章 Vue之在当前组件范围内获取dom元素和组件实例

目录 一、概述 二、获取dom 2.1. 具体步骤 2.2. 完整代码 2.2.1. main.js 2.2.2. App.vue 2.3. BaseChart.vue 三、获取组件实例 3.1. 具体步骤 3.2. 完整代码 3.2.1. main.js 3.2.2. App.vue 3.2.3. BaseForm.vue 3.3. 运行效果 一、概述 我们过去在想要获取一…

基于树莓派的安保巡逻机器人--(一、快速人脸录入与精准人脸识别)

目录 零、前言 一、人脸检测 二、人脸识别 1、采集人脸 2、训练人脸识别模型 3、人脸识别应用 零、前言 随着智能安防需求的增长&#xff0c;基于人工智能和物联网的安保系统逐渐成为趋势。树莓派因其低成本、高扩展性等特点&#xff0c;成为很多AI项目的理想平台。本文将为大…

软件测试学习笔记丨Flask操作数据库-对象与数据模型

本文转自测试人社区&#xff0c;原文链接&#xff1a;https://ceshiren.com/t/topic/23440 对象与数据模型 数据模型&#xff1a;是数据特征的抽象&#xff0c;抽象层次上描述了系统的静态特征、动态行为和约束条件&#xff0c;为数据库系统的信息表示与操作提供一个抽象的框架…

信号量本质 信号量实验(控制车辆运行,优先级反转)互斥量

信号量本质 前面介绍的队列(queue)可以用于传输数据&#xff1a;在任务之间、任务和中断之间。 消息队列用于传输多个数据&#xff0c;但是有时候我们只需要传递状态&#xff0c;这个状态值需要用一个 数值表示&#xff0c;比如&#xff1a; ⚫ 卖家&#xff1a;做好了 1 …

【STL_list 模拟】——打造属于自己的高效链表容器

一、list节点 ​ list是一个双向循环带头的链表&#xff0c;所以链表节点结构如下&#xff1a; template<class T>struct ListNode{T val;ListNode* next;ListNode* prve;ListNode(int x){val x;next prve this;}};二、list迭代器 2.1、list迭代器与vector迭代器区别…

VLAN间通信以及ospf配置

目录 1.基础知识介绍 1.1 什么是VLAN&#xff1f; 1.2 VLAN有什么用&#xff1f; 1.3 不同VLAN如何实现通信&#xff1f; 1.4 什么是路由汇总&#xff1f; 1.4.1 路由汇总的好处&#xff1a; 2. 实验 2.1 网络拓扑设计 2.2 实验配置要求 2.2.1 三层交换配置&#xff…

UE4_Niagara基础实例—13、通过纹理采样来创造粒子

效果&#xff1a; 知识点&#xff1a; 1、纹理采样目前仅支持GPU粒子运行&#xff08;Texture sampling is only supported on the GPU at the moment.&#xff09; 2、网格位置输出每个粒子在网格中的归一化位置。我们使用该值来采样纹理&#xff0c;就像它是UV一样&#xff…

前段(vue)

目录 跨域是什么&#xff1f; SprinBoot跨域的三种解决方法 JavaScript 有 8 种数据类型&#xff0c; 金额的用什么类型。 前段 区别 JQuery使用$.ajax()实现异步请求 Vue 父子组件间的三种通信方式 Vue2 和 Vue3 存在多方面的区别。 跨域是什么&#xff1f; 跨域是指…

基于SpringBoot+Vue实现智能停车收费系统

作者简介&#xff1a;Java领域优质创作者、CSDN博客专家 、CSDN内容合伙人、掘金特邀作者、阿里云博客专家、51CTO特邀作者、多年架构师设计经验、多年校企合作经验&#xff0c;被多个学校常年聘为校外企业导师&#xff0c;指导学生毕业设计并参与学生毕业答辩指导&#xff0c;…

私有化视频平台EasyCVR海康大华宇视视频平台视频诊断技术是如何实时监测视频质量的?

在现代视频监控系统中&#xff0c;确保视频流的质量和稳定性至关重要。随着技术的进步&#xff0c;视频诊断技术已经成为实时监测视频质量的关键工具。这种技术通过智能分析算法对视频流进行实时评估和处理&#xff0c;能够自动识别视频中的各种质量问题&#xff0c;并给出相应…