【一】【SQL】表的增删查改(部分)

表之“增”操作

建表的操作

 
mysql> create table students(
    -> id int unsigned primary key auto_increment,
    -> sn int unsigned unique key,
    -> name varchar(20) not null,
    -> qq varchar(32) unique key
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> desc students;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| sn    | int(10) unsigned | YES  | UNI | NULL    |                |
| name  | varchar(20)      | NO   |     | NULL    |                |
| qq    | varchar(32)      | YES  | UNI | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)

指定列插入

 
mysql> insert into students (sn,name,qq) values (123,'张飞','4567890');
Query OK, 1 row affected (0.00 sec)

mysql> select * from students;
+----+------+--------+---------+
| id | sn   | name   | qq      |
+----+------+--------+---------+
|  1 |  123 | 张飞   | 4567890 |
+----+------+--------+---------+
1 row in set (0.00 sec)

全列插入

 
mysql> insert into students values (10,124,'关羽','123456');
Query OK, 1 row affected (0.00 sec)

mysql> select * from students;
+----+------+--------+---------+
| id | sn   | name   | qq      |
+----+------+--------+---------+
|  1 |  123 | 张飞   | 4567890 |
| 10 |  124 | 关羽   | 123456  |
+----+------+--------+---------+
2 rows in set (0.00 sec)

主键约束展示

 
mysql> insert into students values (10,124,'关羽','123456');
ERROR 1062 (23000): Duplicate entry '10' for key 'PRIMARY'
mysql> insert into students values (11,125,'刘备','123459990');
Query OK, 1 row affected (0.01 sec)

mysql> select * from students;
+----+------+--------+-----------+
| id | sn   | name   | qq        |
+----+------+--------+-----------+
|  1 |  123 | 张飞   | 4567890   |
| 10 |  124 | 关羽   | 123456    |
| 11 |  125 | 刘备   | 123459990 |
+----+------+--------+-----------+
3 rows in set (0.00 sec)

mysql> 

多列插入---全列

 
mysql> insert into students values (13,127,'许攸','1234545656'),(14,128,'许褚','1123334455'),(15,129,'诸葛亮','32111234343');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  127 | 许攸      | 1234545656  |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
+----+------+-----------+-------------+
6 rows in set (0.00 sec)

mysql> 

多列插入---指定列

 
mysql> insert into students (sn,name,qq) values (130,'孙权','64533764'),(131,'吕布','4232455');
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  127 | 许攸      | 1234545656  |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
+----+------+-----------+-------------+
8 rows in set (0.00 sec)

mysql> 

表之“改”操作

键冲突时修改数据(冲突键不变)

 
mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  127 | 许攸      | 1234545656  |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
+----+------+-----------+-------------+
8 rows in set (0.00 sec)
mysql> insert into students values (13,128,'xuyou','11111111');
ERROR 1062 (23000): Duplicate entry '13' for key 'PRIMARY'
mysql> insert into students values (13,132,'xuyou','11111111') on duplicate key update sn=132,name='xuyou',qq='11111111';
Query OK, 2 rows affected (0.00 sec)

mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
+----+------+-----------+-------------+
8 rows in set (0.00 sec)
mysql> insert into students values (18,134,'貂蝉','111223234') on duplicate key update sn=134,name='貂蝉',qq='111223234';
Query OK, 1 row affected (0.00 sec)

mysql> insert into students values (18,134,'貂蝉','111223234') on duplicate key update sn=134,name='貂蝉',qq='111223234';
Query OK, 0 rows affected (0.00 sec)

mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
| 18 |  134 | 貂蝉      | 111223234   |
+----+------+-----------+-------------+
9 rows in set (0.00 sec)

mysql> insert into students values (18,134,'貂蝉','111223234') on duplicate key update sn=134,name='貂蝉',qq='1112235554';
Query OK, 2 rows affected (0.00 sec)

mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
| 18 |  134 | 貂蝉      | 1112235554  |
+----+------+-----------+-------------+
9 rows in set (0.00 sec)

mysql> 

-- 0 row affected :表中有冲突数据,但冲突数据的值和update的值相等

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

-- 2 row affected:表中有冲突数据,并且数据已经被更新

键冲突时修改数据(冲突键会变)

 
mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
| 18 |  134 | 貂蝉      | 1112235554  |
+----+------+-----------+-------------+
9 rows in set (0.00 sec)

mysql> desc students;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| sn    | int(10) unsigned | YES  | UNI | NULL    |                |
| name  | varchar(20)      | NO   |     | NULL    |                |
| qq    | varchar(32)      | YES  | UNI | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> replace into students (sn,name,qq)values(140,'许攸','31213554');
Query OK, 1 row affected (0.00 sec)

mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
| 18 |  134 | 貂蝉      | 1112235554  |
| 19 |  140 | 许攸      | 31213554    |
+----+------+-----------+-------------+
10 rows in set (0.00 sec)

mysql> replace into students (sn,name,qq)values(140,'许攸','31213554');
Query OK, 2 rows affected (0.00 sec)

mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
| 18 |  134 | 貂蝉      | 1112235554  |
| 20 |  140 | 许攸      | 31213554    |
+----+------+-----------+-------------+
10 rows in set (0.00 sec)

mysql> replace into students (sn,name,qq)values(140,'许攸','31213554');
Query OK, 2 rows affected (0.00 sec)

mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
| 18 |  134 | 貂蝉      | 1112235554  |
| 21 |  140 | 许攸      | 31213554    |
+----+------+-----------+-------------+
10 rows in set (0.00 sec)

mysql> 

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

主键或唯一键有冲突,则删除后插入。

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

2 row affectede:表中有冲突数据,删除后重新插入。

update

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

 
mysql> select name ,math from exam_result ;
+-----------+------+
| name      | math |
+-----------+------+
| 唐三藏    |   98 |
| 孙悟空    |   78 |
| 猪悟能    |   98 |
| 曹孟德    |   84 |
| 刘玄德    |   85 |
| 孙权      |   73 |
| 宋公明    |   65 |
+-----------+------+
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: 0

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

mysql> 

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

 
mysql> 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)

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: 0

mysql> 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)

mysql> 

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

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

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

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

mysql> select name , math+english+chinese total from exam_result order by total desc limit 0,3;
+-----------+-------+
| name      | total |
+-----------+-------+
| 猪悟能    |   276 |
| 孙悟空    |   244 |
| 唐三藏    |   221 |
+-----------+-------+
3 rows in set (0.00 sec)

mysql> select name , math+english+chinese total from exam_result order by total limit 3;
+-----------+-------+
| name      | total |
+-----------+-------+
| 宋公明    |   170 |
| 刘玄德    |   185 |
| 曹孟德    |   197 |
+-----------+-------+
3 rows in set (0.00 sec)

mysql> update exam_result set math=math+30 order by chinese+english+math asc limit 3;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> select name , math+english+chinese total from exam_result order by total limit 3;
+-----------+-------+
| name      | total |
+-----------+-------+
| 宋公明    |   200 |
| 刘玄德    |   215 |
| 唐三藏    |   221 |
+-----------+-------+
3 rows in set (0.00 sec)

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

mysql> 

将所有同学的语文成绩更新为原来的2倍

 
mysql> select *from exam_result;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
|  2 | 孙悟空    |      87 |   80 |      77 |
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      70 |   90 |      67 |
|  5 | 刘玄德    |      55 |  115 |      45 |
|  6 | 孙权      |      70 |   73 |      78 |
|  7 | 宋公明    |      75 |   95 |      30 |
+----+-----------+---------+------+---------+
7 rows in set (0.00 sec)

mysql> update exam_result set chinese=chinese*2 ;
Query OK, 7 rows affected (0.01 sec)
Rows matched: 7  Changed: 7  Warnings: 0

mysql> select * from exam_result;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |     134 |   98 |      56 |
|  2 | 孙悟空    |     174 |   80 |      77 |
|  3 | 猪悟能    |     176 |   98 |      90 |
|  4 | 曹孟德    |     140 |   90 |      67 |
|  5 | 刘玄德    |     110 |  115 |      45 |
|  6 | 孙权      |     140 |   73 |      78 |
|  7 | 宋公明    |     150 |   95 |      30 |
+----+-----------+---------+------+---------+
7 rows in set (0.00 sec)

mysql> 

表之“查”操作(部分)

全列查询

 
mysql> select * from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
| 18 |  134 | 貂蝉      | 1112235554  |
| 21 |  140 | 许攸      | 31213554    |
+----+------+-----------+-------------+
10 rows in set (0.00 sec)

指定列查询

 
mysql> select id from students;
+----+
| id |
+----+
|  1 |
| 10 |
| 11 |
| 14 |
| 15 |
| 16 |
| 17 |
| 13 |
| 18 |
| 21 |
+----+
10 rows in set (0.00 sec)

mysql> select id,sn from students;
+----+------+
| id | sn   |
+----+------+
|  1 |  123 |
| 10 |  124 |
| 11 |  125 |
| 14 |  128 |
| 15 |  129 |
| 16 |  130 |
| 17 |  131 |
| 13 |  132 |
| 18 |  134 |
| 21 |  140 |
+----+------+
10 rows in set (0.00 sec)

mysql> select id,sn,name from students;
+----+------+-----------+
| id | sn   | name      |
+----+------+-----------+
|  1 |  123 | 张飞      |
| 10 |  124 | 关羽      |
| 11 |  125 | 刘备      |
| 13 |  132 | xuyou     |
| 14 |  128 | 许褚      |
| 15 |  129 | 诸葛亮    |
| 16 |  130 | 孙权      |
| 17 |  131 | 吕布      |
| 18 |  134 | 貂蝉      |
| 21 |  140 | 许攸      |
+----+------+-----------+
10 rows in set (0.00 sec)

mysql> select id,sn,name,qq from students;
+----+------+-----------+-------------+
| id | sn   | name      | qq          |
+----+------+-----------+-------------+
|  1 |  123 | 张飞      | 4567890     |
| 10 |  124 | 关羽      | 123456      |
| 11 |  125 | 刘备      | 123459990   |
| 13 |  132 | xuyou     | 11111111    |
| 14 |  128 | 许褚      | 1123334455  |
| 15 |  129 | 诸葛亮    | 32111234343 |
| 16 |  130 | 孙权      | 64533764    |
| 17 |  131 | 吕布      | 4232455     |
| 18 |  134 | 貂蝉      | 1112235554  |
| 21 |  140 | 许攸      | 31213554    |
+----+------+-----------+-------------+
10 rows in set (0.00 sec)

mysql> 

表达式查询

示例展示

 
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.05 sec)

mysql> desc exam_result;
+---------+------------------+------+-----+---------+----------------+
| Field   | Type             | Null | Key | Default | Extra          |
+---------+------------------+------+-----+---------+----------------+
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name    | varchar(20)      | NO   |     | NULL    |                |
| chinese | float            | YES  |     | 0       |                |
| math    | float            | YES  |     | 0       |                |
| english | float            | YES  |     | 0       |                |
+---------+------------------+------+-----+---------+----------------+
5 rows in set (0.00 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: 0

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> 

表达式查询

 
mysql> select 1+1;
+-----+
| 1+1 |
+-----+
|   2 |
+-----+
1 row in set (0.00 sec)

mysql> select 7+8;
+-----+
| 7+8 |
+-----+
|  15 |
+-----+
1 row in set (0.00 sec)

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

mysql> select name,math,1+1 from exam_result;
+-----------+------+-----+
| name      | math | 1+1 |
+-----------+------+-----+
| 唐三藏    |   98 |   2 |
| 孙悟空    |   78 |   2 |
| 猪悟能    |   98 |   2 |
| 曹孟德    |   84 |   2 |
| 刘玄德    |   85 |   2 |
| 孙权      |   73 |   2 |
| 宋公明    |   65 |   2 |
+-----------+------+-----+
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)

mysql> select name,math,math+chinese+english  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)

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> 

去重查询(distinct)

 
mysql> select math from exam_result;
+------+
| math |
+------+
|   98 |
|   78 |
|   98 |
|   84 |
|   85 |
|   73 |
|   65 |
+------+
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)

mysql> 

WHERE条件

运算符

说明

>,>=,<,<=

大于,大于等于,小于,小于等于

=

等于,NULL不安全,例如NULL=NULL的结果是NULL

<=>

等于,NULL安全,例如NULL<=>NULL的结果是TRUE(1)

!=,<>

不等于

BETWEEN a0 AND a1

范围匹配,[a0,a1],如果a0<=value<=a1,返回TRUE(1)

IN(option,...)

如果是option中的任意一个,返回TRUE(1)

IS NULL

是NULL

IS NOT NULL

不是NULL

LIKE

模糊匹配。%表示匹配多个(包括0个)任意字符;_表示任意一个字符

AND

多个条件必须为TRUE(1),结果为TRUE(1)

OR

任意一个条件为TRUE(1),结果为TRUE(1)

NOT

条件为TRUE(1),结果为FALSE(0)

 
mysql> select NULL;
+------+
| NULL |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

mysql> select 0;
+---+
| 0 |
+---+
| 0 |
+---+
1 row in set (0.00 sec)

mysql> select NULL=NULL;
+-----------+
| NULL=NULL |
+-----------+
|      NULL |
+-----------+
1 row in set (0.00 sec)

mysql> select null<=>null
    -> ;
+-------------+
| null<=>null |
+-------------+
|           1 |
+-------------+
1 row in set (0.00 sec)

mysql> select 1=1
    -> ;
+-----+
| 1=1 |
+-----+
|   1 |
+-----+
1 row in set (0.00 sec)

mysql> select 2=2;
+-----+
| 2=2 |
+-----+
|   1 |
+-----+
1 row in set (0.00 sec)

mysql> select 2=1;
+-----+
| 2=1 |
+-----+
|   0 |
+-----+
1 row in set (0.00 sec)

mysql> select 2=null;
+--------+
| 2=null |
+--------+
|   NULL |
+--------+
1 row in set (0.00 sec)

mysql> select 1<=>1;
+-------+
| 1<=>1 |
+-------+
|     1 |
+-------+
1 row in set (0.00 sec)

mysql> select 1<=>0;
+-------+
| 1<=>0 |
+-------+
|     0 |
+-------+
1 row in set (0.00 sec)

mysql> select 1!=1;
+------+
| 1!=1 |
+------+
|    0 |
+------+
1 row in set (0.00 sec)

mysql> select 1!=2;
+------+
| 1!=2 |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

mysql> select null is null;
+--------------+
| null is null |
+--------------+
|            1 |
+--------------+
1 row in set (0.00 sec)

mysql> select null is not null;
+------------------+
| null is not null |
+------------------+
|                0 |
+------------------+
1 row in set (0.00 sec)

mysql> 

条件查询

 
mysql> select name , english from exam_result ;
+-----------+---------+
| name      | english |
+-----------+---------+
| 唐三藏    |      56 |
| 孙悟空    |      77 |
| 猪悟能    |      90 |
| 曹孟德    |      67 |
| 刘玄德    |      45 |
| 孙权      |      78 |
| 宋公明    |      30 |
+-----------+---------+
7 rows in set (0.00 sec)

mysql> select name , english from exam_result where english<60;
+-----------+---------+
| name      | english |
+-----------+---------+
| 唐三藏    |      56 |
| 刘玄德    |      45 |
| 宋公明    |      30 |
+-----------+---------+
3 rows in set (0.00 sec)

mysql> 

where条件查询案例

语文成绩在[80,90]分的同学及语文成绩

 
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> select name,chinese from exam_result;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 唐三藏    |      67 |
| 孙悟空    |      87 |
| 猪悟能    |      88 |
| 曹孟德    |      82 |
| 刘玄德    |      55 |
| 孙权      |      70 |
| 宋公明    |      75 |
+-----------+---------+
7 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)

mysql> select name,chinese from exam_result where chinese between 80 and 90;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 孙悟空    |      87 |
| 猪悟能    |      88 |
| 曹孟德    |      82 |
+-----------+---------+
3 rows in set (0.00 sec)

mysql> 

数学成绩是58或59或98或99的同学及数学成绩

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

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

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

mysql> 

姓孙的同学及孙某同学

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

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

mysql> 

语文成绩好于英语成绩的同学

 
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> 

总分在200分以下的同学

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

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

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

mysql> 

mysql语句执行顺序

 
mysql> select name ,chinese+math+english total from exam_result where total<200;
ERROR 1054 (42S22): Unknown column 'total' in 'where clause'
mysql> select name ,chinese+math+english total from exam_result where chinese+math+english<200;
+-----------+-------+
| name      | total |
+-----------+-------+
| 刘玄德    |   185 |
| 宋公明    |   170 |
+-----------+-------+
2 rows in set (0.00 sec)

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

mysql> 

首先要知道在哪一个表中做操作,第二步是条件判断,前两步得出的是符合条件的表,第三步在得到的符合条件的表中选择列数据。在执行第二步的时候,并不知道total是什么。

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

 
mysql> select name ,chinese from exam_result where chinese>80;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 孙悟空    |      87 |
| 猪悟能    |      88 |
| 曹孟德    |      82 |
+-----------+---------+
3 rows in set (0.00 sec)

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 not like '孙%';
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 唐三藏    |      67 |
| 猪悟能    |      88 |
| 曹孟德    |      82 |
| 刘玄德    |      55 |
| 宋公明    |      75 |
+-----------+---------+
5 rows in set (0.00 sec)

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)

mysql> 

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

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

mysql> select name ,chinese ,math,english ,chinese+math+english 总分 from exam_result where chinese +math+english >200;
+-----------+---------+------+---------+--------+
| name      | chinese | math | english | 总分   |
+-----------+---------+------+---------+--------+
| 唐三藏    |      67 |   98 |      56 |    221 |
| 孙悟空    |      87 |   78 |      77 |    242 |
| 猪悟能    |      88 |   98 |      90 |    276 |
| 曹孟德    |      82 |   84 |      67 |    233 |
| 孙权      |      70 |   73 |      78 |    221 |
+-----------+---------+------+---------+--------+
5 rows in set (0.00 sec)

mysql> select name ,chinese ,math,english ,chinese+math+english 总分 from exam_result where chinese +math+english >200 and chinese <math;
+-----------+---------+------+---------+--------+
| name      | chinese | math | english | 总分   |
+-----------+---------+------+---------+--------+
| 唐三藏    |      67 |   98 |      56 |    221 |
| 猪悟能    |      88 |   98 |      90 |    276 |
| 曹孟德    |      82 |   84 |      67 |    233 |
| 孙权      |      70 |   73 |      78 |    221 |
+-----------+---------+------+---------+--------+
4 rows in set (0.00 sec)

mysql> select name ,chinese ,math,english ,chinese+math+english 总分 from exam_result where chinese +math+english >200 and chinese <math and english>80;
+-----------+---------+------+---------+--------+
| name      | chinese | math | english | 总分   |
+-----------+---------+------+---------+--------+
| 猪悟能    |      88 |   98 |      90 |    276 |
+-----------+---------+------+---------+--------+
1 row in set (0.00 sec)

mysql> select name ,chinese ,math,english ,chinese+math+english 总分 from exam_result where name like '孙_';
+--------+---------+------+---------+--------+
| name   | chinese | math | english | 总分   |
+--------+---------+------+---------+--------+
| 孙权   |      70 |   73 |      78 |    221 |
+--------+---------+------+---------+--------+
1 row in set (0.00 sec)

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
0;
+-----------+---------+------+---------+--------+
| name      | chinese | math | english | 总分   |
+-----------+---------+------+---------+--------+
| 猪悟能    |      88 |   98 |      90 |    276 |
| 孙权      |      70 |   73 |      78 |    221 |
+-----------+---------+------+---------+--------+
2 rows in set (0.00 sec)

mysql> 

NULL和''的区别

 
mysql> create table test_null(
    -> id int,
    -> name varchar (20)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> 
mysql> insert into test_null (id,name) values (1,'张三');
Query OK, 1 row affected (0.01 sec)

mysql> insert into test_null (id,name) values (null,'张三');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test_null (id,name) values (1,null);
Query OK, 1 row affected (0.01 sec)

mysql> insert into test_null (id,name) values (null,null);
Query OK, 1 row affected (0.01 sec)

mysql> insert into test_null (id,name) values (1,'');
Query OK, 1 row affected (0.01 sec)

mysql> select * from test_null;
+------+--------+
| id   | name   |
+------+--------+
|    1 | 张三   |
| NULL | 张三   |
|    1 | NULL   |
| NULL | NULL   |
|    1 |        |
+------+--------+
5 rows in set (0.00 sec)

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

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

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

mysql> 

Order by

asc升序

desc降序

默认升序

同学及数学成绩,按照数学成绩升序显示

 
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> 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)

mysql> 

NULL的排序

 
mysql> select * from test_null;
+------+--------+
| id   | name   |
+------+--------+
|    1 | 张三   |
| NULL | 张三   |
|    1 | NULL   |
| NULL | NULL   |
|    1 |        |
+------+--------+
5 rows in set (0.00 sec)

mysql> select * from test_null order by name asc;
+------+--------+
| id   | name   |
+------+--------+
|    1 | NULL   |
| NULL | NULL   |
|    1 |        |
|    1 | 张三   |
| NULL | 张三   |
+------+--------+
5 rows in set (0.00 sec)

mysql> select * from test_null order by name desc;
+------+--------+
| id   | name   |
+------+--------+
|    1 | 张三   |
| NULL | 张三   |
|    1 |        |
|    1 | NULL   |
| NULL | NULL   |
+------+--------+
5 rows in set (0.00 sec)

mysql> 

NULL在排序中视作为比任何值都要小。

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

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

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

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

mysql> select name ,math,english,chinese from exam_result order by math desc,english desc;
+-----------+------+---------+---------+
| 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)

mysql> select name ,math,english,chinese from exam_result order by math desc,english desc,chinese;
+-----------+------+---------+---------+
| 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)

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)

mysql> 

默认的排序

默认升序

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

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)

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

mysql> 

查询同学及总分,由高到低(mysql语句执行顺序)

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

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

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

mysql> select name ,math+english+chinese 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> 

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

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

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

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

mysql> select * from exam_result limit 3 offset 1;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  2 | 孙悟空    |      87 |   78 |      77 |
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      82 |   84 |      67 |
+----+-----------+---------+------+---------+
3 rows in set (0.00 sec)

mysql> select * from exam_result limit 5 offset 0;
+----+-----------+---------+------+---------+
| 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 |
+----+-----------+---------+------+---------+
5 rows in set (0.00 sec)

mysql> 

筛选分页

limit的使用

 
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> select * from exam_result limit 5;
+----+-----------+---------+------+---------+
| 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 |
+----+-----------+---------+------+---------+
5 rows in set (0.00 sec)

mysql> select * from exam_result limit 1;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
+----+-----------+---------+------+---------+
1 row in set (0.00 sec)

mysql> select * from exam_result limit 2;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |      67 |   98 |      56 |
|  2 | 孙悟空    |      87 |   78 |      77 |
+----+-----------+---------+------+---------+
2 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 1,3;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  2 | 孙悟空    |      87 |   78 |      77 |
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      82 |   84 |      67 |
+----+-----------+---------+------+---------+
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 2,1;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  3 | 猪悟能    |      88 |   98 |      90 |
+----+-----------+---------+------+---------+
1 row in set (0.00 sec)

mysql> select * from exam_result limit 2,2;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  3 | 猪悟能    |      88 |   98 |      90 |
|  4 | 曹孟德    |      82 |   84 |      67 |
+----+-----------+---------+------+---------+
2 rows in set (0.00 sec)

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

mysql>

分页的具体操作

 
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> select * from exam_result limit 0,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 3,3;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  4 | 曹孟德    |      82 |   84 |      67 |
|  5 | 刘玄德    |      55 |   85 |      45 |
|  6 | 孙权      |      70 |   73 |      78 |
+----+-----------+---------+------+---------+
3 rows in set (0.00 sec)

mysql> select * from exam_result limit 6,3;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  7 | 宋公明    |      75 |   65 |      30 |
+----+-----------+---------+------+---------+
1 row 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)

mysql> select * from exam_result limit 3 offset 3;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  4 | 曹孟德    |      82 |   84 |      67 |
|  5 | 刘玄德    |      55 |   85 |      45 |
|  6 | 孙权      |      70 |   73 |      78 |
+----+-----------+---------+------+---------+
3 rows in set (0.00 sec)

mysql> select * from exam_result limit 3 offset 6;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  7 | 宋公明    |      75 |   65 |      30 |
+----+-----------+---------+------+---------+
1 row in set (0.00 sec)

mysql> 

同学名字及总分,总分大于200分,总分降序排序,分页操作

 
mysql> select name ,math+english+chinese total from exam_result where english+math+chinese >200 order by total;
+-----------+-------+
| name      | total |
+-----------+-------+
| 唐三藏    |   221 |
| 孙权      |   221 |
| 曹孟德    |   233 |
| 孙悟空    |   242 |
| 猪悟能    |   276 |
+-----------+-------+
5 rows in set (0.00 sec)

mysql> select name ,math+english+chinese total from exam_result where english+math+chinese >200 order by total desc;
+-----------+-------+
| name      | total |
+-----------+-------+
| 猪悟能    |   276 |
| 孙悟空    |   242 |
| 曹孟德    |   233 |
| 唐三藏    |   221 |
| 孙权      |   221 |
+-----------+-------+
5 rows in set (0.01 sec)

mysql> select name ,math+english+chinese total from exam_result where english+math+chinese >200 order by total desc limit 1;
+-----------+-------+
| name      | total |
+-----------+-------+
| 猪悟能    |   276 |
+-----------+-------+
1 row in set (0.00 sec)

mysql> select name ,math+english+chinese total from exam_result where english+math+chinese >200 order by total desc limit 2 offset 0;
+-----------+-------+
| name      | total |
+-----------+-------+
| 猪悟能    |   276 |
| 孙悟空    |   242 |
+-----------+-------+
2 rows in set (0.00 sec)

mysql> select name ,math+english+chinese total from exam_result where english+math+chinese >200 order by total desc limit 2 offset 2;
+-----------+-------+
| name      | total |
+-----------+-------+
| 曹孟德    |   233 |
| 唐三藏    |   221 |
+-----------+-------+
2 rows in set (0.00 sec)

mysql> select name ,math+english+chinese total from exam_result where english+math+chinese >200 order by total desc limit 2 offset 4;
+--------+-------+
| name   | total |
+--------+-------+
| 孙权   |   221 |
+--------+-------+
1 row in set (0.00 sec)

mysql> 

表之“删”操作

删表

 
mysql> create table t1( id int, name varchar(20) );
Query OK, 0 rows affected (0.02 sec)

mysql> show tables;
+--------------+
| Tables_in_d1 |
+--------------+
| exam_result  |
| students     |
| t1           |
+--------------+
3 rows in set (0.00 sec)

mysql> drop table if exists t1;
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
+--------------+
| Tables_in_d1 |
+--------------+
| exam_result  |
| students     |
+--------------+
2 rows in set (0.00 sec)

mysql> 

Delete

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

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

mysql> delete from exam_result where name='孙悟空';
Query OK, 1 row affected (0.00 sec)

mysql> select *from exam_result;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |     134 |   98 |      56 |
|  3 | 猪悟能    |     176 |   98 |      90 |
|  4 | 曹孟德    |     140 |   90 |      67 |
|  5 | 刘玄德    |     110 |  115 |      45 |
|  6 | 孙权      |     140 |   73 |      78 |
|  7 | 宋公明    |     150 |   95 |      30 |
+----+-----------+---------+------+---------+
6 rows in set (0.00 sec)

mysql> select name ,chinese +math+english total from exam_result ;
+-----------+-------+
| name      | total |
+-----------+-------+
| 唐三藏    |   288 |
| 猪悟能    |   364 |
| 曹孟德    |   297 |
| 刘玄德    |   270 |
| 孙权      |   291 |
| 宋公明    |   275 |
+-----------+-------+
6 rows in set (0.00 sec)

mysql> select name ,chinese +math+english total from exam_result order by total;
+-----------+-------+
| name      | total |
+-----------+-------+
| 刘玄德    |   270 |
| 宋公明    |   275 |
| 唐三藏    |   288 |
| 孙权      |   291 |
| 曹孟德    |   297 |
| 猪悟能    |   364 |
+-----------+-------+
6 rows in set (0.00 sec)

mysql> select name ,chinese +math+english total from exam_result order by total desc;
+-----------+-------+
| name      | total |
+-----------+-------+
| 猪悟能    |   364 |
| 曹孟德    |   297 |
| 孙权      |   291 |
| 唐三藏    |   288 |
| 宋公明    |   275 |
| 刘玄德    |   270 |
+-----------+-------+
6 rows in set (0.01 sec)

mysql> select name ,chinese +math+english total from exam_result order by total asc;
+-----------+-------+
| name      | total |
+-----------+-------+
| 刘玄德    |   270 |
| 宋公明    |   275 |
| 唐三藏    |   288 |
| 孙权      |   291 |
| 曹孟德    |   297 |
| 猪悟能    |   364 |
+-----------+-------+
6 rows in set (0.00 sec)

mysql> select name ,chinese +math+english total from exam_result order by total asc limit 1;
+-----------+-------+
| name      | total |
+-----------+-------+
| 刘玄德    |   270 |
+-----------+-------+
1 row in set (0.00 sec)

mysql> delete from exam_result order by english +math+chinese asc limit 1;
Query OK, 1 row affected (0.00 sec)

mysql> select name ,chinese+math+english total from exam_result order by total asc limit 1;
+-----------+-------+
| name      | total |
+-----------+-------+
| 宋公明    |   275 |
+-----------+-------+
1 row in set (0.00 sec)

mysql> select * from exam_result;
+----+-----------+---------+------+---------+
| id | name      | chinese | math | english |
+----+-----------+---------+------+---------+
|  1 | 唐三藏    |     134 |   98 |      56 |
|  3 | 猪悟能    |     176 |   98 |      90 |
|  4 | 曹孟德    |     140 |   90 |      67 |
|  6 | 孙权      |     140 |   73 |      78 |
|  7 | 宋公明    |     150 |   95 |      30 |
+----+-----------+---------+------+---------+
5 rows in set (0.00 sec)

mysql> 

删除整个表

 
mysql> create table for_delete(
    -> id int primary key auto_increment,
    -> name varchar(20)
    -> );
Query OK, 0 rows affected (0.02 sec)

mysql> insert into for_delete (name) value ('A'),('B'),('C');
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

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.02 sec)

mysql> delete from for_delete;
Query OK, 3 rows affected (0.01 sec)

mysql> select *from for_delete;
Empty 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> insert into for_delete (name) value ('E');
Query OK, 1 row affected (0.00 sec)

mysql> select * from for_delete;
+----+------+
| id | name |
+----+------+
|  4 | E    |
+----+------+
1 row in set (0.00 sec)

mysql> 

截断表

无法回滚,会重置auto_increment项。

 
mysql> create table for_truncate(
    -> id int primary key auto_increment,
    -> name varchar(20)
    -> );
Query OK, 0 rows affected (0.04 sec)

mysql> desc for_truncate;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> insert into for_truncate (name) value('A'),('B'),('C');
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from for_truncate;
+----+------+
| id | name |
+----+------+
|  1 | A    |
|  2 | B    |
|  3 | C    |
+----+------+
3 rows in 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 AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> truncate for_truncate;
Query OK, 0 rows affected (0.02 sec)

mysql> show tables;
+--------------+
| Tables_in_d1 |
+--------------+
| exam_result  |
| for_delete   |
| for_truncate |
| students     |
| test_null    |
+--------------+
5 rows in set (0.00 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> insert into for_truncate (name) values ('E');
Query OK, 1 row affected (0.01 sec)

mysql> select *from for_truncate;
+----+------+
| id | name |
+----+------+
|  1 | E    |
+----+------+
1 row in set (0.01 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 AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> 

结尾

最后,感谢您阅读我的文章,希望这些内容能够对您有所启发和帮助。如果您有任何问题或想要分享您的观点,请随时在评论区留言。

同时,不要忘记订阅我的博客以获取更多有趣的内容。在未来的文章中,我将继续探讨这个话题的不同方面,为您呈现更多深度和见解。

谢谢您的支持,期待与您在下一篇文章中再次相遇!

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

试一下newb,还是有错误呀

解题&#xff1a;原式&#xff1d; 2. 在递增的等比数列 ( a n ) (a_n) (an​)中&#xff0c;若 ( a 3 − a 1 5 2 ) (a_3 - a_1 \frac{5}{2}) (a3​−a1​25​), ( a 2 3 ) (a_2 3) (a2​3), 则公比 (q) A. ( 4 3 ) ( \frac{4}{3} ) (34​) B. ( 3 2 ) ( \frac{3}{2} …

创建vue3项目(基础)

首先打开自己的目录文件输入指令cmd 出现命令行工具 输入指令vue create 项目名称 按回车 选择第三个自己配置 根据需求选择 回车 选择自己需要的版本 出现这个 一直按回车大约5下或者6下 创建完毕 结束 感谢观看

Flutter(二):Row、Column 布局

MaterialApp 对于 MaterialApp&#xff0c;组件提供了一些默认的属性&#xff0c;如AppBar、标题、背景颜色等&#xff0c;你可以默认使用它们 import package:flutter/material.dart;void main() {runApp(const App()); }class App extends StatelessWidget {const App({super…

《名作欣赏》期刊投稿方向投稿邮箱

《名作欣赏》杂志是由国家新闻出版总署批准的正规学术期刊。文学是用语言塑造形象反映社会生活的一种语言艺术&#xff0c;是自觉、独立而又面向整个社会的艺术&#xff0c;是文化中极具强烈感染力的重要组成部分&#xff0c;亦是对美的体现。在现代社会&#xff0c;物欲横流&a…

用matlab实现交通分布预测方法——增长系数法

前言 对于我的第一篇文章&#xff1a;Matlab实现交通分布预测方法 —— 增长系数法 | 平均增长率法、底特律法、福莱特法&#xff0c;有不少同学私信我询问关于如何在 matlab 中调用函数、拆分代码以及需要大量调用的问题。于是我便想着把内容做一些优化&#xff0c;放在这篇文…

【MySQL】MySQL从0到0.9 - 持续更新ing

MySQL SQL 基础 DDL 语句 show databases; show tables; desc table_name; # 获取表信息 show create table 表名; // 查询指定表的建表语句 数据类型 char(10) 不满10个会用空格填充&#xff0c;性能好一点 varchar(10) 变长字符串&#xff0c;性能差一点 CREATE TABLE tabl…

nginx设置缓存时间

一、设置缓存时间 当网页数据返回给客户端后&#xff0c;可针对静态网页设置缓存时间&#xff0c;在配置文件内的http段内server段添加location&#xff0c;更改字段expires 1d来实现&#xff1a;避免重复请求&#xff0c;加快访问速度 第一步&#xff1a;修改主配置文件 #修…

[NOIP2011 普及组] 数字反转

AC代码&#xff1a; #include<iostream>using namespace std;int main() {long long n;cin >> n;long long temp n;long long sum 0;while(temp ! 0){int c temp % 10;sum sum * 10 c;temp temp / 10;}printf("%lld",sum);return 0; }

Spring 中 ApplicationContext 和 BeanFactory 的区别有哪些

先看一张类图&#xff1a; 区别&#xff1a; 1&#xff1a;包目录不同&#xff1a; spring-beans.jar 中 org.springframework.beans.factory.BeanFactory spring-context.jar 中 org.springframework.context.ApplicationContext 2&#xff1a;国际化&#xff1a; BeanFacto…

APP被针对攻击了,要怎么解决

随着APP行业的兴起&#xff0c;游戏公司异军突起&#xff0c;不管是在控证还是攻击方面都是属于最复杂的一个场面&#xff0c;游戏APP逐渐成为DDOS流量攻击的“重灾区”。没有提前做好了解就盲目进军游戏APP行业&#xff0c;一旦被攻击就会让公司束手无策。那么&#xff0c;刚上…

Python从入门到精通指南【第101篇—入门到精通】【文末送书-24】

文章目录 Python从入门到精通指南第一步&#xff1a;入门基础1.1 安装Python1.2 Hello World1.3 变量和数据类型1.4 控制流程 第二步&#xff1a;深入学习2.1 函数和模块2.2 列表、元组和字典2.3 文件操作 第三步&#xff1a;高级主题3.1 面向对象编程3.2 异常处理3.3 正则表达…

python_pyecharts绘制漏斗图

python-pyecharts绘制漏斗图 from pyecharts.charts import Funnel from pyecharts import options as opts# 数据 data [("访问", 100), ("咨询", 80), ("订单", 60), ("点击", 40), ("展现", 20)]# 创建漏斗图 funnel …

Qt OpenGL程序在Windows下正常,但在Linux下无显示问题【已解决】

Qt OpenGL程序在Windows下正常&#xff0c;但在Linux下无显示问题【已解决】 引言一、问题描述二、解决方案三、解决过程记录3.1 定位问题3.2 解决问题&#xff0c;深入分析 引言 在Windows上正常运行的OpenGL程序&#xff0c;到Linux下正常编译…但是没有任何显示(只有背景颜…

【数据结构与算法】动态规划法解题20240227

动态规划法 一、什么是动态规划二、动态规划的解题步骤三、509. 斐波那契数1、动规五部曲&#xff1a; 四、70. 爬楼梯1、动规五部曲&#xff1a; 五、746. 使用最小花费爬楼梯1、动规五部曲&#xff1a; 一、什么是动态规划 动态规划&#xff0c;英文&#xff1a;Dynamic Pro…

23年中科院1区算法|长鼻浣熊优化算法COA原理及其利用与改进(Matlab/Python)

文章来源于我的个人公众号&#xff1a;KAU的云实验台&#xff0c;主要更新智能优化算法的原理、应用、改进 CEC2005中的测试 本文 KAU将介绍一个2023年1月发表在中科院1区KBS上的优化算法——长鼻浣熊优化算法(Coati Optimization Algorithm&#xff0c;COA)[1] 该算法由Dehg…

SpringBoot源码解读与原理分析(三十四)SpringBoot整合JDBC(三)声明式事务的传播行为控制

文章目录 前言10.5 声明式事务的传播行为控制10.5.1 修改测试代码&#xff08;1&#xff09;新建一个Service类&#xff0c;并引用UserService&#xff08;2&#xff09;修改主启动类 10.5.2 PROPAGATION_REQUIRED10.5.2.1 tm.getTransaction&#xff08;1&#xff09;获取事务…

IO进程线程作业day7

信号灯集共享内存 自定义头文件 #ifndef SEM_H_ #define SEM_H_ //创建信号灯集, int creat_t(int number); //申请释放资源 int P(int semid,int semno); //申请释放资源 int V(int semid,int semno); //删除信号灯集 int del(int semid); #endif信号灯集函数集合 #include…

物资管理新篇章:Java+SpringBoot实战

✍✍计算机编程指导师 ⭐⭐个人介绍&#xff1a;自己非常喜欢研究技术问题&#xff01;专业做Java、Python、微信小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。 ⛽⛽实战项目&#xff1a;有源码或者技术上的问题欢迎在评论区一起讨论交流&#xff01; ⚡⚡ Java实战 |…

基于 ResNet50和 SVM + 决策树的人脸口罩检测

欢迎收看&#xff0c;这篇文章是关于我如何使用 ResNet50作为特征提取器来构建掩码检测&#xff0c;然后使用支持向量机(SVM) 决策树和叠加集成方法作为分类器的一个快速解释。 为了向研究人员致敬&#xff0c;这个应用程序是基于研究论文&#xff0c;题目是“在2019冠状病毒…

分布式应用:kylin 部署 zabbix 监控平台

目录 一、实验 1.环境 2. kylin 修改mysql数据库 3. kylin 部署 zabbix 监控平台 4. kylin 修改 zabbix 配置 5. kylin 修改zabbix web 二、问题 1. zabbix_server 查看版本报错 2.zabbix_server 文件如何去掉注释"#"和空行 3. zabbix图表显示异常 4.zabbi…