MySQL SQL 練習問題
This commit is contained in:
32
MYSQL_Question1.txt
Normal file
32
MYSQL_Question1.txt
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
--問1
|
||||||
|
CREATE TABLE book_table (
|
||||||
|
book_id INT,
|
||||||
|
book_name VARCHAR(50),
|
||||||
|
author_name VARCHAR(50),
|
||||||
|
price INT,
|
||||||
|
sales_flag INT
|
||||||
|
);
|
||||||
|
|
||||||
|
--問2
|
||||||
|
INSERT INTO book_table VALUES(10001, 'TwoPeace', '三田英一郎', 420, 1);
|
||||||
|
INSERT INTO book_table VALUES(10002, '名探偵金田二', '青山ふみや', 460, 1);
|
||||||
|
INSERT INTO book_table VALUES(20001, '坊ちゃま', '冬目漱岩', 460, 1);
|
||||||
|
INSERT INTO book_table VALUES(30001, '西方見聞録', '不明', 1000, 1);
|
||||||
|
INSERT INTO book_table VALUES(40010, '吾輩は犬である', '冬目漱岩', 420
|
||||||
|
, 1);
|
||||||
|
|
||||||
|
--問3
|
||||||
|
SELECT book_name, author_name FROM book_table;
|
||||||
|
|
||||||
|
--問4
|
||||||
|
UPDATE book_table SET author_name = 'マール=コー=ポロ', sales_flag = 0 WHERE book_id = 30001;
|
||||||
|
|
||||||
|
--問5
|
||||||
|
select book_id, book_name, author_name, price, sales_flag from book_table where sales_flag = 1;
|
||||||
|
|
||||||
|
--問6
|
||||||
|
select book_id, book_name, author_name, price, sales_flag from book_table where author_name = '冬目漱岩' and price = 420;
|
||||||
|
|
||||||
|
--問7
|
||||||
|
delete from book_table where book_id = 20001;
|
||||||
|
select * from book_table;
|
||||||
29
MYSQL_Question2.txt
Normal file
29
MYSQL_Question2.txt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
--問1
|
||||||
|
create table item_category (
|
||||||
|
category_id INT AUTO_INCREMENT,
|
||||||
|
category_name VARCHAR(256) not null,
|
||||||
|
primary key(category_id)
|
||||||
|
);
|
||||||
|
insert into item_category values(1, '家具');
|
||||||
|
insert into item_category values(2, '飲料');
|
||||||
|
insert into item_category values(3, '食品');
|
||||||
|
|
||||||
|
--問2
|
||||||
|
create table items(
|
||||||
|
item_id INT AUTO_INCREMENT,
|
||||||
|
name VARCHAR(256) not null,
|
||||||
|
price INT not null,
|
||||||
|
category_id INT,
|
||||||
|
primary key(item_id),
|
||||||
|
foreign key(category_id) references item_category(category_id)
|
||||||
|
);
|
||||||
|
insert into items values(1,'ローマのテーブル', 150000, 1);
|
||||||
|
insert into items values(2,'げーたるーど2000 500ml', 370, 2);
|
||||||
|
insert into items values(3,'原始肉', 2500, 3);
|
||||||
|
insert into items values(4,'魅惑の椅子', 100000, 1);
|
||||||
|
|
||||||
|
--問3
|
||||||
|
select * from items inner join item_category using(category_id);
|
||||||
|
|
||||||
|
--問4
|
||||||
|
select * from items inner join item_category using(category_id) order by price;
|
||||||
Reference in New Issue
Block a user