From 286a1587f71c033ec44ffe27b83371df36494ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=B7=9D=E3=80=80=E8=A3=95=E6=A8=B9?= <26-y-ishikawa-stellatecnica@it-college.co.jp> Date: Mon, 26 Oct 2026 16:49:27 +0900 Subject: [PATCH] =?UTF-8?q?MySQL=20SQL=20=E7=B7=B4=E7=BF=92=E5=95=8F?= =?UTF-8?q?=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MYSQL_Question1.txt | 32 ++++++++++++++++++++++++++++++++ MYSQL_Question2.txt | 29 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 MYSQL_Question1.txt create mode 100644 MYSQL_Question2.txt diff --git a/MYSQL_Question1.txt b/MYSQL_Question1.txt new file mode 100644 index 0000000..dd87d80 --- /dev/null +++ b/MYSQL_Question1.txt @@ -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; \ No newline at end of file diff --git a/MYSQL_Question2.txt b/MYSQL_Question2.txt new file mode 100644 index 0000000..45d8524 --- /dev/null +++ b/MYSQL_Question2.txt @@ -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; \ No newline at end of file