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 ...
随机推荐
- Coursera Deep Learning笔记 序列模型(二)NLP & Word Embeddings(自然语言处理与词嵌入)
参考 1. Word Representation 之前介绍用词汇表表示单词,使用one-hot 向量表示词,缺点:它使每个词孤立起来,使得算法对相关词的泛化能力不强. 从上图可以看出相似的单词分布距 ...
- 野指针和free总结超有用的资料
在C语言项目中,经常会遇到需要程序员手动分配内存的地方.这样做能够节省大量的内存空间,也让程序更加灵活.只要你有一定的基础,那么肯定用过 malloc 或者 ralloc和free的组合.这个组合使用 ...
- 【做题记录】CF1428E Carrots for Rabbits—堆的妙用
CF1428E Carrots for Rabbits 题意: 有 \(n\) 个萝卜,每个萝卜的初始大小为 \(a_i\) .现在要把这些萝卜切为为 \(k\) 个.吃每一个萝卜的时间为这个萝卜的大 ...
- Spring Cloud Gateway夺命连环10问?
大家好,我是不才陈某~ 最近有很多小伙伴私信我催更 <Spring Cloud 进阶>,陈某也总结了一下,最终原因就是陈某之前力求一篇文章将一个组件重要知识点讲透,这样导致了文章篇幅很长, ...
- threading python2 和python3
from __future__ import division from __future__ import print_function import threading balance = 0 d ...
- 猫狗收容所 牛客网 程序员面试金典 C++
猫狗收容所 牛客网 程序员面试金典 C++ 题目描述 有家动物收容所只收留猫和狗,但有特殊的收养规则,收养人有两种收养方式,第一种为直接收养所有动物中最早进入收容所的,第二种为选择收养的动物类型(猫或 ...
- ubuntn 一直循环登录界面 (卸载nvidia驱动)
由于在Ubuntu下安装了Nvidia显卡驱动后开机一直处于循环登录界面,密码输入正确也是进不去,然后就决定卸载Nvidia显卡驱动.首先是在能使用tty1登录的情况下,使用 $ sudo apt-g ...
- Centos7上安装Ubuntu容器
1.再次之前我们要先装好docker,在上一篇我已经给出了教程,没有安装好的快去看看吧! 2.这里我们使用的是linux系统,所有在线安装是最简便的方法了.我们可以从国内拉取dockerhub镜像,这 ...
- Linux&C open creat read write lseek 函数用法总结
一:五个函数的参数以及返回值. 函数 参数 返回值 open (文件名,打开方式以及读 ...
- Docker学习:起步篇
Docker-概述 学习资源 最好的资源在官网! Docker官方: Docker 官方主页: https://www.docker.com(opens new window) Docker 官方博客 ...