MYSQL5.8----M2
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| m1 |
| mon |
| mysql |
| performance_schema |
| quan; |
| quanbbs |
| quantest |
| quantesttwo |
| sys |
+--------------------+
10 rows in set (0.02 sec) mysql> use mon
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> SHOW TABLES;
+---------------+
| Tables_in_mon |
+---------------+
| ALT |
| fa |
| father |
| nu |
| numm |
| nummm |
| qqq |
| son |
| ss |
| tp3 |
| tp4 |
| tp5 |
| tp6 |
| user |
+---------------+
14 rows in set (0.00 sec) mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
mysql> SELECT username,id,sex FROM user;
+----------+----+------+
| username | id | sex |
+----------+----+------+
| 小强 | 1 | 0 |
| 小xx | 2 | 0 |
| 小jj | 3 | 0 |
| 小米 | 4 | 0 |
| 小xiao | 6 | 0 |
| root | 7 | 0 |
+----------+----+------+
6 rows in set (0.00 sec)
mysql> SELECT user.id,user.username as un FROM user;
+----+---------+
| id | un |
+----+---------+
| 1 | 小强 |
| 2 | 小xx |
| 3 | 小jj |
| 4 | 小米 |
| 6 | 小xiao |
| 7 | root |
+----+---------+
6 rows in set (0.00 sec)
mysql> mysql> SELECT u.id,u.username AS un FROM user AS u;
+----+---------+
| id | un |
+----+---------+
| 1 | 小强 |
| 2 | 小xx |
| 3 | 小jj |
| 4 | 小米 |
| 6 | 小xiao |
| 7 | root |
+----+---------+
6 rows in set (0.00 sec)
mysql> SELECT * FROM user WHERE sex = 0;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
6 rows in set (0.00 sec) mysql> SELECT * FROM user WHERE age = 25;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------
| id | username | pwd | sex | age | edu | classname | province
+----+----------+----------------------------------+------+------+-----+-----------+-----------
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津
+----+----------+----------------------------------+------+------+-----+-----------+-----------
6 rows in set (0.00 sec) mysql> SELECT age FROM user GROUP BY age;
+------+
| age |
+------+
| 25 |
| 35 |
| 83 |
| 116 |
+------+
4 rows in set (0.00 sec)
mysql> mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
6 rows in set (0.00 sec) mysql> SELECT age FROM user GROUP BY age;
+------+
| age |
+------+
| 25 |
| 35 |
| 83 |
| 116 |
+------+
4 rows in set (0.00 sec) mysql> SELECT age FROM user GROUP BY age HAVING count(id) > 2;
+------+
| age |
+------+
| 25 |
+------+
1 row in set (0.13 sec)
mysql> SELECT * FROM user HAVING id % 2 = 0 ;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
3 rows in set (0.00 sec) mysql> SELECT * FROM user WHERE id % 2 = 0 ;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
6 rows in set (0.00 sec) mysql> SELECT * FROM user ORDER BY id DESC;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
6 rows in set (0.00 sec) mysql> SELECT * FROM user ORDER BY age ASC;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
6 rows in set (0.00 sec)
mysql> SELECT * FROM user ORDER BY age ASC,id DESC;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
6 rows in set (0.00 sec)
mysql> SELECT * FROM user ;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
6 rows in set (0.00 sec) mysql> SELECT * FROM user LIMIT 2 ;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
2 rows in set (0.00 sec) mysql> SELECT * FROM user LIMIT 3,4 ;
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
3 rows in set (0.00 sec) mysql> SELECT * FROM user LIMIT 3,3 ;
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
3 rows in set (0.00 sec) mysql> SELECT * FROM user LIMIT 3,2 ;
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
2 rows in set (0.00 sec) mysql> SELECT * FROM user LIMIT 2,2 ;
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
2 rows in set (0.00 sec) mysql> SELECT * FROM user ORDER BY age DESC LIMIT 2 ;
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
+----+----------+----------------------------------+------+------+-----+-----------+----------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM user ;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+-------+
| id | username | pwd | sex | age | edu | classname | province | price |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+-------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 | 0.00 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 | 0.00 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 | 0.00 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 | 0.00 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 | 0.00 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 | 0.00 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+-------+
6 rows in set (0.00 sec) mysql> UPDATE user SET price = age*edu WHERE id % 2 =0;
Query OK, 3 rows affected (0.09 sec)
Rows matched: 3 Changed: 3 Warnings: 0 mysql> SELECT * FROM user ;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
| id | username | pwd | sex | age | edu | classname | province | price |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 | 0.00 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 | 70.00 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 | 0.00 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 | 249.00 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 | 348.00 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 | 0.00 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
6 rows in set (0.00 sec) mysql> UPDATE user SET price = age*edu*1.5 WHERE id % 2 =1;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0 mysql> SELECT * FROM user ;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
| id | username | pwd | sex | age | edu | classname | province | price |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 | 75.00 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 | 70.00 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 | 75.00 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 | 249.00 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 | 348.00 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 | 75.00 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
6 rows in set (0.00 sec) mysql> SELECT AVG(price) FROM user;
+------------+
| AVG(price) |
+------------+
| 148.666667 |
+------------+
1 row in set (0.36 sec) mysql> SELECT ROUND(AVG(price)) FROM user;
+-------------------+
| ROUND(AVG(price)) |
+-------------------+
| 149 |
+-------------------+
1 row in set (0.01 sec) mysql> SELECT ROUND(AVG(price),2) FROM user;
+---------------------+
| ROUND(AVG(price),2) |
+---------------------+
| 148.67 |
+---------------------+
1 row in set (0.00 sec)
mysql> SELECT id,username,price FROM user WHERE price > 148.67;
+----+----------+--------+
| id | username | price |
+----+----------+--------+
| 4 | 小米 | 249.00 |
| 6 | 小xiao | 348.00 |
+----+----------+--------+
2 rows in set (0.09 sec) mysql> SELECT id,username,price FROM user WHERE price < 148.67;
+----+----------+-------+
| id | username | price |
+----+----------+-------+
| 1 | 小强 | 75.00 |
| 2 | 小xx | 70.00 |
| 3 | 小jj | 75.00 |
| 7 | root | 75.00 |
+----+----------+-------+
4 rows in set (0.00 sec) mysql> SELECT id,username,price FROM user WHERE price >(SELECT ROUND(AVG(price),2) FROM user);
+----+----------+--------+
| id | username | price |
+----+----------+--------+
| 4 | 小米 | 249.00 |
| 6 | 小xiao | 348.00 |
+----+----------+--------+
2 romysql> SELECT price FROM user WHERE classname = 'jave';
+-------+
| price |
+-------+
| 75.00 |
| 70.00 |
+-------+
2 rows in set (0.00 sec)
ws in set (0.00 sec)
mysql> SELECT username,price FROM user WHERE classname = 'jave';
+----------+-------+
| username | price |
+----------+-------+
| 小强 | 75.00 |
| 小xx | 70.00 |
+----------+-------+
2 rows in set (0.00 sec)
mysql> SELECT username,price FROM user WHERE price > ANY (SELECT price FROM user WHERE classname = 'jave');
+----------+--------+
| username | price |
+----------+--------+
| 小强 | 75.00 |
| 小jj | 75.00 |
| 小米 | 249.00 |
| 小xiao | 348.00 |
| root | 75.00 |
+----------+--------+
5 rows in set (0.09 sec) mysql> SELECT username,classname,price FROM user WHERE price > ANY (SELECT price FROM user WHERE classname = 'jave');
+----------+-----------+--------+
| username | classname | price |
+----------+-----------+--------+
| 小强 | jave | 75.00 |
| 小jj | javed | 75.00 |
| 小米 | py | 249.00 |
| 小xiao | py | 348.00 |
| root | dada | 75.00 |
+----------+-----------+--------+
5 rows in set (0.00 sec) mysql> SELECT username,classname,price FROM user WHERE price >= ANY (SELECT price FROM user WHERE classname = 'jave');
+----------+-----------+--------+
| username | classname | price |
+----------+-----------+--------+
| 小强 | jave | 75.00 |
| 小xx | jave | 70.00 |
| 小jj | javed | 75.00 |
| 小米 | py | 249.00 |
| 小xiao | py | 348.00 |
| root | dada | 75.00 |
+----------+-----------+--------+
6 rows in set (0.00 sec)
mysql> CREATE TABLE provices(
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> name VARCHAR(10) NOT NULL);
Query OK, 0 rows affected (0.14 sec)
mysql> SELECT * FROM provices;
Empty set (0.00 sec) mysql> SELECT province FROM user;
+-----------+
| province |
+-----------+
| 内蒙古 |
| 内蒙古 |
| 湛江 |
| 背景 |
| 福门 |
| 天津 |
+-----------+
6 rows in set (0.00 sec) mysql> SELECT province FROM user GROUP BY province;
+-----------+
| province |
+-----------+
| 内蒙古 |
| 天津 |
| 湛江 |
| 福门 |
| 背景 |
+-----------+
5 rows in set (0.00 sec)
mysql> INSERT INTO provices(name) SELECT province FROM user GROUP BY province;
Query OK, 5 rows affected (0.10 sec)
Records: 5 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM provices;
+----+-----------+
| id | name |
+----+-----------+
| 1 | 内蒙古 |
| 2 | 天津 |
| 3 | 湛江 |
| 4 | 福门 |
| 5 | 背景 |
+----+-----------+
5 rows in set (0.00 sec) mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+----
| id | username | pwd | sex | age | edu | classname | pro
+----+----------+----------------------------------+------+------+-----+-----------+----
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津
+----+----------+----------------------------------+------+------+-----+-----------+----
6 rows in set (0.00 sec)
mysql> UPDATE user INNER JOIN provices ON user.province = provices.name SET user.provinc
Query OK, 6 rows affected (0.01 sec)
Rows matched: 6 Changed: 6 Warnings: 0 mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+----
| id | username | pwd | sex | age | edu | classname | pro
+----+----------+----------------------------------+------+------+-----+-----------+----
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 1
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 1
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 3
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 5
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 4
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 2
+----+----------+----------------------------------+------+------+-----+-----------+----
6 rows in set (0.00 sec)
mysql> CREATE TABLE class(
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> classname VARCHAR(20) NOT NULL)
-> SELECT classname FROM user GROUP BY classname;
Query OK, 4 rows affected (0.05 sec)
Records: 4 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM class
-> ;
+----+-----------+
| id | classname |
+----+-----------+
| 1 | dada |
| 2 | jave |
| 3 | javed |
| 4 | py |
+----+-----------+
4 rows in set (0.00 sec)
mysql> UPDATE user INNER JOIN class ON user.classname = class.classname SET user.classna
Query OK, 6 rows affected (0.00 sec)
Rows matched: 6 Changed: 6 Warnings: 0 mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+----
| id | username | pwd | sex | age | edu | classname | pro
+----+----------+----------------------------------+------+------+-----+-----------+----
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | 2 | 1
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | 2 | 1
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | 3 | 3
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | 4 | 5
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | 4 | 4
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | 1 | 2
+----+----------+----------------------------------+------+------+-----+-----------+----
6 rows in set (0.00 sec)
mysql> DESC user;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(20) | NO | | NULL | |
| pwd | char(32) | NO | | NULL | |
| sex | tinyint(4) | YES | | 0 | |
| age | tinyint(4) | YES | | 18 | |
| edu | tinyint(4) | NO | | 2 | |
| classname | varchar(10) | NO | | NULL | |
| province | varchar(10) | NO | | NULL | |
| price | decimal(8,2) | NO | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
9 rows in set (0.15 sec)
mysql> ALTER TABLE user CHANGE classname cid TINYINT UNSIGNED NOT NULL, CHANGE province
Query OK, 6 rows affected (0.04 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----+-------+--
| id | username | pwd | sex | age | edu | cid | proid | p
+----+----------+----------------------------------+------+------+-----+-----+-------+--
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | 2 | 1 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | 2 | 1 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | 3 | 3 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | 4 | 5 | 2
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | 4 | 4 | 3
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | 1 | 2 |
+----+----------+----------------------------------+------+------+-----+-----+-------+--
6 rows in set (0.00 sec)
mysql> SELECT user.id,user.username,class.classname AS cname FROM user INNER JOIN class ON user.cid = class.id;
+----+----------+-------+
| id | username | cname |
+----+----------+-------+
| 1 | 小强 | jave |
| 2 | 小xx | jave |
| 3 | 小jj | javed |
| 4 | 小米 | py |
| 6 | 小xiao | py |
| 7 | root | dada |
+----+----------+-------+
6 rows in set (0.03 sec) mysql> SELECT u.id,u.username,c.classname FROM user AS u LEFT JOIN class AS c ON u.cid = c.id;^C
mysql> INSERT INTO user (username,pwd,age,edu,cid,proid,price) VALUES('QQ',md5(1234),66,3,7,4,888.99);
Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----+-------+--------+
| id | username | pwd | sex | age | edu | cid | proid | price |
+----+----------+----------------------------------+------+------+-----+-----+-------+--------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | 2 | 1 | 75.00 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | 2 | 1 | 70.00 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | 3 | 3 | 75.00 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | 4 | 5 | 249.00 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | 4 | 4 | 348.00 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | 1 | 2 | 75.00 |
| 8 | QQ | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 66 | 3 | 7 | 4 | 888.99 |
+----+----------+----------------------------------+------+------+-----+-----+-------+--------+
7 rows in set (0.00 sec) mysql> SELECT * FROM class;
+----+-----------+
| id | classname |
+----+-----------+
| 1 | dada |
| 2 | jave |
| 3 | javed |
| 4 | py |
+----+-----------+
4 rows in set (0.00 sec) mysql> SELECT u.id,u.username,c.classname FROM user AS u LEFT JOIN class AS c ON u.cid = c.id;
+----+----------+-----------+
| id | username | classname |
+----+----------+-----------+
| 7 | root | dada |
| 1 | 小强 | jave |
| 2 | 小xx | jave |
| 3 | 小jj | javed |
| 4 | 小米 | py |
| 6 | 小xiao | py |
| 8 | QQ | NULL |
+----+----------+-----------+
7 rows in set (0.00 sec) mysql> SELECT u.id,u.username,c.classname FROM user AS u RIGHT JOIN class AS c ON u.cid = c.id;
+------+----------+-----------+
| id | username | classname |
+------+----------+-----------+
| 1 | 小强 | jave |
| 2 | 小xx | jave |
| 3 | 小jj | javed |
| 4 | 小米 | py |
| 6 | 小xiao | py |
| 7 | root | dada |
+------+----------+-----------+
6 rows in set (0.00 sec)
多表连接:
mysql> SELECT u.id,u.username,u.pwd,u.sex,u.age,u.edu,c.classname,p.name,u.price FROM user AS u INNER JOIN class AS c ON c.id =u.cid INNER JOIN provices AS p ON p.id = u.proid;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
| id | username | pwd | sex | age | edu | classname | name | price |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 | 75.00 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 | 70.00 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 | 75.00 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 | 249.00 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 | 348.00 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 | 75.00 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
6 rows in set (0.00 sec) mysql> SELECT u.id,u.username,u.pwd,u.sex,u.age,u.edu,c.classname,p.name,u.price FROM user AS u ,class AS c,provices AS p WHERE u.cid = c.id AND u.proid = p.id;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
| id | username | pwd | sex | age | edu | classname | name | price |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 | 75.00 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 | 70.00 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 | 75.00 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 | 249.00 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 | 348.00 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 | 75.00 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+--------+
6 rows in set (0.00 sec)
子表:
mysql> CREATE TABLE class_type(
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> name VARCHAR(20) NOT NULL,
-> pid INT UNSIGNED NOT NULL DEFAULT 0);
Query OK, 0 rows affected (0.49 sec)
mysql> DESC class_type;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
| pid | int(10) unsigned | NO | | 0 | |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
mysql> INSERT INTO class_type values(null,"java开发",2);
Query OK, 1 row affected (0.09 sec)
mysql> INSERT INTO class_type values(null,"h5开发",2);
Query OK, 1 row affected (0.36 sec) mysql> INSERT INTO class_type values(null,"linux运维",2);
Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM class_type;
+----+-------------+-----+
| id | name | pid |
+----+-------------+-----+
| 1 | java开发 | 2 |
| 2 | h5开发 | 2 |
| 3 | linux运维 | 2 |
+----+-------------+-----+
3 rows in set (0.00 sec) mysql> INSERT INTO class_type VALUES(null,"JAVASE",1),(null,"thinkphp",2),(
-> "laravel",2),
-> (null,"oststorp",2),
-> (null,"myslq",4),
-> (null,"redis",4),
-> (null,"HTML",3),
-> (null,"css",3),
-> (null,"javascript",3);
Query OK, 9 rows affected (0.00 sec)
Records: 9 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM class_type;
+----+-------------+-----+
| id | name | pid |
+----+-------------+-----+
| 1 | java开发 | 2 |
| 2 | h5开发 | 2 |
| 3 | linux运维 | 2 |
| 4 | JAVASE | 1 |
| 5 | thinkphp | 2 |
| 6 | laravel | 2 |
| 7 | oststorp | 2 |
| 8 | myslq | 4 |
| 9 | redis | 4 |
| 10 | HTML | 3 |
| 11 | css | 3 |
| 12 | javascript | 3 |
+----+-------------+-----+
12 rows in set (0.00 sec)
mysql> update class_type set pid = 0 WHERE id = 1 OR id = 2 OR id = 3;
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3 Changed: 3 Warnings: 0 mysql> SELECT * FROM class_type;
+----+-------------+-----+
| id | name | pid |
+----+-------------+-----+
| 1 | java开发 | 0 |
| 2 | h5开发 | 0 |
| 3 | linux运维 | 0 |
| 4 | JAVASE | 1 |
| 5 | thinkphp | 2 |
| 6 | laravel | 2 |
| 7 | oststorp | 2 |
| 8 | myslq | 4 |
| 9 | redis | 4 |
| 10 | HTML | 3 |
| 11 | css | 3 |
| 12 | javascript | 3 |
+----+-------------+-----+
mysql> SELECT s.id,s.name,p.name FROM class_type AS s LEFT JOIN class_type AS p ON s.id = p.id;
+----+-------------+-------------+
| id | name | name |
+----+-------------+-------------+
| 1 | java开发 | java开发 |
| 2 | h5开发 | h5开发 |
| 3 | linux运维 | linux运维 |
| 4 | JAVASE | JAVASE |
| 5 | thinkphp | thinkphp |
| 6 | laravel | laravel |
| 7 | oststorp | oststorp |
| 8 | myslq | myslq |
| 9 | redis | redis |
| 10 | HTML | HTML |
| 11 | css | css |
| 12 | javascript | javascript |
+----+-------------+-------------+
12 rows in set (0.00 sec)
mysql> SELECT p.id,p.name,s.name FROM class_type AS p LEFT JOIN class_type AS s ON p.id = s.pid;
+----+-------------+------------+
| id | name | name |
+----+-------------+------------+
| 1 | java开发 | JAVASE |
| 2 | h5开发 | thinkphp |
| 2 | h5开发 | laravel |
| 2 | h5开发 | oststorp |
| 4 | JAVASE | myslq |
| 4 | JAVASE | redis |
| 3 | linux运维 | HTML |
| 3 | linux运维 | css |
| 3 | linux运维 | javascript |
| 5 | thinkphp | NULL |
| 6 | laravel | NULL |
| 7 | oststorp | NULL |
| 8 | myslq | NULL |
| 9 | redis | NULL |
| 10 | HTML | NULL |
| 11 | css | NULL |
| 12 | javascript | NULL |
+----+-------------+------------+
17 rows in set (0.00 sec)
MYSQL5.8----M2的更多相关文章
- CentOS7下源码安装mysql5.6
目录 准备工作 运行环境 确认你的安装版本 下载mysql 安装mysql 准备安装环境 编译和安装 配置mysql 单实例配置 单实例配置方法 添加防火墙 ...
- MySQL5.7 利用keepalived来实现mysql双主高可用方案的详细过程
Reference: http://blog.csdn.net/mchdba/article/details/51377989 服务器准备 Keepalived:192.168.13.15 Keep ...
- Mysql5.6.x版本半同步主从复制的开启方法
介绍 先了解一下mysql的主从复制是什么回事,我们都知道,mysql主从复制是基于binlog的复制方式,而mysql默认的主从复制方式,其实是异步复制. 主库实际上并不关心从库是否把数据拉完没有, ...
- CENTOS 6.5 平台离线编译安装 Mysql5.6.22
一.下载源码包 http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.22.tar.gz 二.准备工作 卸载之前本机自带的MYSQL 安装 cmake,编 ...
- 在 Windows7 上按照 MySQL5.7
在 Windows7 上按照 MySQL5.7 1.从官网下载最新版本的 MySQL,这里下载的是 mysql-5.7.17-win32: 2.将下载的 mysql-5.7.17-win32.zip ...
- Win7安装MySQL-5.7.16过程
1.在C盘新建MYSQL文件夹:2.将mysql-5.7.16-winx64拷贝到C:\MYSQL文件夹下,更名为mysql-5.7.16:3.在mysql-5.7.16目录下,建my.ini文件,内 ...
- mysql-5.6.34 Installation from Source code
Took me a while to suffer from the first successful souce code installation of mysql-5.6.34. Just pu ...
- mysql5.x升级至mysql5.7后导入之前数据库date出错的解决方法!
mysql5.x升级至mysql5.7后导入之前数据库date出错的解决方法! 修改mysql5.7的配置文件即可解决,方法如下: linux版:找到mysql的安装路径进入默认的为/usr/shar ...
- 搭建LNAMP环境(一)- 源码安装MySQL5.6
1.yum安装编译mysql需要的包 yum -y install gcc-c++ make cmake bison-devel ncurses-devel perl 2.为mysql创建一个新的用户 ...
- windows7 下 apache2.4 和 php5.5 及 mysql5.6 的安装与配置
要准备的软件 httpd-2.4.9-win32-VC11.zip http://www.apachelounge.com/download/ php-5.5.13-Win32-VC11-x86.zi ...
随机推荐
- [Beta]the Agiles Scrum Meeting 12
会议时间:2020.5.27 21:00 1.每个人的工作 今天已完成的工作 成员 已完成的工作 issue yjy 帮助解决技术问题 tq 撰写技术博客 wjx 博客评分界面美化 dzx 博客评分界 ...
- rabbitmq死信队列和延时队列的使用
死信队列&死信交换器:DLX 全称(Dead-Letter-Exchange),称之为死信交换器,当消息变成一个死信之后,如果这个消息所在的队列存在x-dead-letter-exchange ...
- gson中TypeAdapter实现自定义序列化操作
最近在项目中遇到这么一个问题,我们后台需要向前端返回一个 json 数据,就是将一个地理位置对象以json的格式返回到前台,但是这个地理位置对象中的经纬度是Double数据类型,项目中规定,如果经纬度 ...
- Noip模拟42 2021.8.17
T1 卷 一看跟没有上司的舞会一样,直接敲了然后试个自己造的样例对了就跑了... 然而把它想简单了,乘积取模,还能比大小吗????? 显然不能 所以直接让对数的加和跟着$dp$直接一起跑,比大小的都用 ...
- 计算机网络之流量控制(停止-等待协议、滑动窗口、后退N帧协议GBN、选择重传协议SR)、滑动窗口、可靠传输机制
文章转自:https://blog.csdn.net/weixin_43914604/article/details/104908762 学习课程:<2019王道考研计算机网络> 学习目的 ...
- 『学了就忘』Linux基础 — 10、VMware虚拟机中克隆的使用
目录 1.什么是克隆 2.克隆的两种类型 (1)完整克隆 (2)链接克隆 3.克隆操作 步骤一:克隆虚拟机 步骤二:进行克隆导向 3.快照与克隆的区别 4.镜像的管理 快照和克隆是VMware中两个非 ...
- word-break leetcoder C++
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- hdu 3047 Zjnu Stadium(并查集)
题意: 300个座位构成一个圈. 有N个人要入座. 共有M个说明 :A B X ,代表B坐在A顺时针方向第X个座位上.如果这个说明和之前的起冲突,则它是无效的. 问总共有多少个无效的. 思路: 并查集 ...
- 如何选择普通索引和唯一索引《死磕MySQL系列 五》
系列文章 一.原来一条select语句在MySQL是这样执行的<死磕MySQL系列 一> 二.一生挚友redo log.binlog<死磕MySQL系列 二> 三.MySQL强 ...
- WPF_02_XAML
XAML(Extensible Application Markup Language的简写)是用于实例化.NET对象的标记语言.XAML对于WPF不是必须的. XAML基础 XAML标准: XAML ...