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 ...
随机推荐
- Kubernetes集群环境搭建全过程
资源准备以及服务器初始化 所有服务器执行一下脚本进行配置信息初始化: #!/bin/bash cd `dirname $0` # 关闭selinux setenforce 0 sed -i '/SEL ...
- stm32学习笔记之GPIO功能框图分析
GPIO 是通用输入输出端口的简称,简单来说就是STM32 可控制的引脚,STM32 芯片的GPIO 引脚与外部设备连接起来,从而实现与外部通讯.控制以及数据采集的功能.STM32 芯片的GPIO被分 ...
- 什么是操作系统fork()进程
1.fork()是创建进程函数. 2.c程序一开始,就会产生 一个进程,当这个进程执行到fork()的时候,会创建一个子进程. 3.此时父进程和子进程是共存的,它们俩会一起向下执行c程序的代码. 4. ...
- linux&c 进程控制 课后习题
(声明:本篇博客只是博主自己的理解,加以整理,目的是总结刚学过的进程知识,不一定绝对正确,非常愿意听客官您提出宝贵意见.) Q1:进程中的全局数据段(全局变量),局部数据段(局部变量),静态数据段的分 ...
- kvm 安装 windows 虚拟机
作者:SRE运维博客 博客地址: https://www.cnsre.cn/ 文章地址:https://www.cnsre.cn/posts/211108848062/ 相关话题:https://ww ...
- grpc协议
gRPC详解 gRPC是什么? gRPC是什么可以用官网的一句话来概括 A high-performance, open-source universal RPC framework 所谓RPC(re ...
- 【java+selenium3】Tesseract-OCR识别图片验证码 (十六)
[java+selenium+Tesseract-OCR(图片识别)+AutoIt(windows窗口识别)]完成自动化图片验证码识别! 一.AutoIt(windows窗口识别)参考:https:/ ...
- OSI模型 & TCP/IP模型
分层思想 分层思想:将复杂 的流程分解 为几个功能相对单一 的子过程 整个流程更加清晰 ,复杂问题简单化 更容易发现问题并针对性的解决问题 分层思想在网络中的应用 OSI模型 国际标准化组织(Inte ...
- topk算法
方法一 堆排序 自建堆 heapMax方法,从上至下调整堆 pop时,可以使用自上而下调整堆,调用heapMax(arr,0,sz-1); push时,需要自下到上调整即 从上到下调整: void h ...
- PTA 7-2 邻接表创建无向图 (20分)
PTA 7-2 邻接表创建无向图 (20分) 采用邻接表创建无向图G ,依次输出各顶点的度. 输入格式: 输入第一行中给出2个整数i(0<i≤10),j(j≥0),分别为图G的顶点数和边数. 输 ...