MySQL SQL問題集 part1 MySQEnter password: ********* Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 23 Server version: 8.0.32 MySQL Community Server - GPL Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> USE rezodb; Database changed mysql> CREATE TABLE emp_table (emp_no INT,emp_name VARCHAR(50),salary INT); Query OK, 0 rows affected (0.03 sec) mysql> INSERT INTO emp_table VALUES (1, '井上', 200000); Query OK, 1 row affected (0.01 sec) mysql> INSERT INTO emp_table VALUES (2, '梅田', 1000000); Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM emp_table; +--------+----------+---------+ | emp_no | emp_name | salary | +--------+----------+---------+ | 1 | 井上 | 200000 | | 2 | 梅田 | 1000000 | +--------+----------+---------+ 2 rows in set (0.00 sec) mysql> CREATE TABLE book_table (book_id INT,book_name VARCHAR(50), author_name VARCHAR(50), prime INT,sales_flag INT); Query OK, 0 rows affected (0.04 sec) mysql> INSERT INTO book_table VALUES (10001,TwoPeace,'三田英一郎',420,1); ERROR 1054 (42S22): Unknown column 'TwoPeace' in 'field list' mysql> INSERT INTO book_table VALUES(10001,TwoPeace,'三田英一郎',420,1); ERROR 1054 (42S22): Unknown column 'TwoPeace' in 'field list' mysql> DROP TABLE book_table; Query OK, 0 rows affected (0.02 sec) mysql> CREATE TABLE book_table(book_id INT,book_name VARCHAR(50),author_name VARCHAR(50),price INT,sales_flag INT); Query OK, 0 rows affected (0.03 sec) mysql> INSERT INTO book_table(10001,TwoPeace,'三田英一郎',420,1); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10001,TwoPeace,'三田英一郎',420,1)' at line 1 mysql> INSERT INTO book_table VALUES (10001,'TwoPeace','三田英一郎',420,1); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES (10001,'TwoPeace','三田英一郎',420,1)' at line 1 mysql> SELECT * fROM book_table; Empty set (0.00 sec) mysql> INSERT INTO book_table VALUES (10001,'TwoPeace','三田英一郎',420,1); Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM book_table; +---------+-----------+-------------+-------+------------+ | book_id | book_name | author_name | price | sales_flag | +---------+-----------+-------------+-------+------------+ | 10001 | TwoPeace | 三田英一郎 | 420 | 1 | +---------+-----------+-------------+-------+------------+ 1 row in set (0.00 sec) mysql> INSERT INTO book_table VALUES(10002,'名探偵金田二','青山ふみや',420,1); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO book_table VALUES(20001,'坊ちゃま','冬目漱石',460); ERROR 1136 (21S01): Column count doesn't match value count at row 1 mysql> INSERT INTO book_table VALUES(20001,'坊ちゃま','冬目漱石',460,1); Query OK, 1 row affected (0.01 sec) mysql> UPDATE book_table SET price = 460 WHERE book_id = 10002; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> INSERT INTO book_table VALUES(30001,'西方見聞録','不明',1000,1); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO book_table VALIES(40010,'吾輩は犬である','冬目漱石',420,1); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALIES(40010,'吾輩は犬である','冬目漱石',420,1)' at line 1 mysql> INSERT INTO book_table VALUES(40010,'吾輩は犬である','冬目漱石',420,1); Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM book_table; +---------+----------------+-------------+-------+------------+ | book_id | book_name | author_name | price | sales_flag | +---------+----------------+-------------+-------+------------+ | 10001 | TwoPeace | 三田英一郎 | 420 | 1 | | 10002 | 名探偵金田二 | 青山ふみや | 460 | 1 | | 20001 | 坊ちゃま | 冬目漱石 | 460 | 1 | | 30001 | 西方見聞録 | 不明 | 1000 | 1 | | 40010 | 吾輩は犬である | 冬目漱石 | 420 | 1 | +---------+----------------+-------------+-------+------------+ 5 rows in set (0.00 sec) mysql> SELECT book_name,author_name FROM book_table; +----------------+-------------+ | book_name | author_name | +----------------+-------------+ | TwoPeace | 三田英一郎 | | 名探偵金田二 | 青山ふみや | | 坊ちゃま | 冬目漱石 | | 西方見聞録 | 不明 | | 吾輩は犬である | 冬目漱石 | +----------------+-------------+ 5 rows in set (0.00 sec) mysql> UPDATA book_table SET author_name = 'マール=コー=ポロ' WHERE book_id = 30001; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATA book_table SET author_name = 'マール=コー=ポロ' WHERE book_id ' at line 1 mysql> UPDATA book_table SET author_name = 'マール=コー=ポロ' WHERE book_id =30001; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATA book_table SET author_name = 'マール=コー=ポロ' WHERE book_id ' at line 1 mysql> UPDATA book_table SET sales_flag = 0 WHERE book_id = 30001; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATA book_table SET sales_flag = 0 WHERE book_id = 30001' at line 1 mysql> ^C mysql> UPDATE book_table SET author_name = 'マール=コー=ポロ' WHERE book_id = 30001; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> UPDATE book_table SET sales_flag = 0 WHERE book_id = 30001; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT FROM *book_table; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM *book_table' at line 1 mysql> SELECT FROM * book_table; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM * book_table' at line 1 mysql> SELECT * FROM book_table; +---------+----------------+--------------------+-------+------------+ | book_id | book_name | author_name | price | sales_flag | +---------+----------------+--------------------+-------+------------+ | 10001 | TwoPeace | 三田英一郎 | 420 | 1 | | 10002 | 名探偵金田二 | 青山ふみや | 460 | 1 | | 20001 | 坊ちゃま | 冬目漱石 | 460 | 1 | | 30001 | 西方見聞録 | マール=コー=ポロ | 1000 | 0 | | 40010 | 吾輩は犬である | 冬目漱石 | 420 | 1 | +---------+----------------+--------------------+-------+------------+ 5 rows in set (0.00 sec) mysql> SELECT * FROM book_table where salse_flag = 1; ERROR 1054 (42S22): Unknown column 'salse_flag' in 'where clause' mysql> SELECT * FROM book_table where salse_flag = 1; ERROR 1054 (42S22): Unknown column 'salse_flag' in 'where clause' mysql> SELECT * FROM table WHERE sales_flag = 1; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table WHERE sales_flag = 1' at line 1 mysql> SELECT * FROM book_table WHERE sales_flag = 1; +---------+----------------+-------------+-------+------------+ | book_id | book_name | author_name | price | sales_flag | +---------+----------------+-------------+-------+------------+ | 10001 | TwoPeace | 三田英一郎 | 420 | 1 | | 10002 | 名探偵金田二 | 青山ふみや | 460 | 1 | | 20001 | 坊ちゃま | 冬目漱石 | 460 | 1 | | 40010 | 吾輩は犬である | 冬目漱石 | 420 | 1 | +---------+----------------+-------------+-------+------------+ 4 rows in set (0.00 sec) mysql> SELECT * FROM book_table where author_name = '冬目漱石' and price = 420; +---------+----------------+-------------+-------+------------+ | book_id | book_name | author_name | price | sales_flag | +---------+----------------+-------------+-------+------------+ | 40010 | 吾輩は犬である | 冬目漱石 | 420 | 1 | +---------+----------------+-------------+-------+------------+ 1 row in set (0.00 sec) mysql> DELETE FROM book_table WHERE book_id = 20001; Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM book_table; +---------+----------------+--------------------+-------+------------+ | book_id | book_name | author_name | price | sales_flag | +---------+----------------+--------------------+-------+------------+ | 10001 | TwoPeace | 三田英一郎 | 420 | 1 | | 10002 | 名探偵金田二 | 青山ふみや | 460 | 1 | | 30001 | 西方見聞録 | マール=コー=ポロ | 1000 | 0 | | 40010 | 吾輩は犬である | 冬目漱石 | 420 | 1 | +---------+----------------+--------------------+-------+------------+ 4 rows in set (0.00 sec)