2 Commits

Author SHA1 Message Date
61b6a7cf70 MySQL SQL練習問題20261027 2026-10-27 16:28:36 +09:00
286a1587f7 MySQL SQL 練習問題 2026-10-26 16:49:27 +09:00
4 changed files with 85 additions and 0 deletions

32
MYSQL_Question1.txt Normal file
View 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
View 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;

14
MYSQL_Question2_5-.txt Normal file
View File

@@ -0,0 +1,14 @@
--問5
select * from items inner join item_category using(category_id) where category_name = '家具';
--問6
select * from items inner join item_category using(category_id) where price between 1000 and 50000;
--問7
select count(*) as data_count from items;
--問8
select * from items inner join item_category using(category_id) where price = (select max(price) from items);
--問9
select * from items inner join item_category using(category_id) where name like '%の%';

10
Question2+α.txt Normal file
View File

@@ -0,0 +1,10 @@
--問1
select items.item_id as 商品ID, items.name as 商品名, items.price as 価格,
item_category.name as カテゴリ名 from items inner join item_category using(category_id);
--問2
select orders.order_id as 注文ID, orders.order_time as 注文日時, users.name as ユーザー名,
items.name as 商品名, items.price as 価格, order_items.quantity as 数量 from order_items
inner join orders using(order_id)
inner join items using(item_id)
inner join users using(user_id) order by orders.order_time;